Skip to content

Fix all compiler warnings for default build

Nathan Baker requested to merge nathan-b/libtiff:warnings into master

Of the 8 logical changes in this changeset, 5 of them do not change compiled code.

  • Two are spelling errors in a couple of comments.
  • Two are adding fallthrough comments to case statements to indicate intentional fallthrough to the next case label.
  • One fixes the indentation of a for loop because the compiler thought the indentation was potentially confusing.

Of the three remaining changes:

  • The first replaces the left shift of a negative integer (which is undefined behavior according to the standard) with an alternate calculation intended to produce the same behavior as the original code. I don't know the bigger picture of what this code is doing, but I do know that this calculation is intended to produce a mask integer which has that many bits set (i.e. for 4, the result should be 00001111b, or 0xf). I can prove that for all valid inputs (1, 2, and 4) the new code produces the same output as the old code, and can furthermore prove that for all additional inputs from 5-100 it also produces the same output.
  • The second change (the buffer size for the temp file name) generates a warning because we're taking a buffer of size 4097 and then snprintf-ing it into another buffer of size 4097 along with some other slush that makes the potential size of the data larger than 4097. This change adds enough to the size of the second buffer to make it hold the slush, and then it will fail out later with ENAMETOOLONG on file open in the unlikely event the user specifies a name longer than PATH_MAX.
  • The third change appears to be an actual bug caught by the compiler. It uses a logical or instead of a bitwise or to build a bit string. I replaced the logical or with the bitwise or, which I believe is the original intent of the code.
Edited by Nathan Baker

Merge request reports