← Back to team overview

kicad-developers team mailing list archive

Patches to correct some warnings

 

All,
Here are four patches to correct some warnings I am seeing while compiling with the OS X compiler in C++11 mode. I think they have general applicability for all targets. I checked that the patches will apply against 5037 and that the 5037 programs run (on Ubuntu Linux 14.04).

The first patch fixes a typo in the header guard for pcb_calculator/datafile_read_write.h. The typo would cause the guard to fail.

Attachment: datafile_read_write.patch
Description: Binary data


The second patch fixes some unsigned comparisons in two files with similar logic (cvpcb/class_footprints_listbox.cpp and cvpcb/class_library_listbox.cpp.) Linecount is an unsigned parameter in these functions. The warning is that the test of linecount >= 0 is always true. The code is trying to ensure that linecount is always within the range of the array. However, if the array is empty (GetCount == 0) then it could subtract 1 from linecount, which would underflow and produce a large positive number, not a negative one, since linecount is unsigned.

Attachment: class_listbox.patch
Description: Binary data


The third patch corrects a warning in pcbnew/modview_frame.cpp that the add operator doesn’t work as intended with a string and an integer. The patch converts the integer to a string prior to the add operator.

Attachment: modview_frame.patch
Description: Binary data


The fourth patch, which I am the least confident of, adds UNSELECTED and UNDEFINED enums to the layer list instead of the macro that coerces -1 and -2 to a LAYER_ID. The warning I am seeing is that equality comparisons of the layer_id to UNDEFINED_LAYER and UNSELECTED_LAYER will never be true. What I am seeing is that the -1 is treated as unsigned, which means it has a value of a large positive number (4294967295). Because the enum has a type of unsigned char, its max value is 255 so the 4294967295 is out of range, hence the warning that they will never compare. To fix this, I created enum values UNSELECTED and UNDEFINED and gave them values of -2 and -1.  The change fixes the warning and doesn’t seem to impact the functioning of the programs, but I don’t know for sure what impact the change has across the entire code base.

Attachment: layers_id_colors_and_visibility.patch
Description: Binary data


Michael

Follow ups