Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix warnings for builds with clang compiler #754

Merged
merged 3 commits into from
Oct 14, 2024

Conversation

stweil
Copy link
Collaborator

@stweil stweil commented Oct 13, 2024

The clang compiler reports several annoying warnings. Some of them have already been reported as an issue:

../src/bmpio.c:169:37: warning: taking address of packed member 'bmpih' of class or structure 'BMP_HEADER' may result in an unaligned pointer value [-Waddress-of-packed-member]
../src/bmpio.c:186:31: warning: taking address of packed member 'bmpih' of class or structure 'BMP_HEADER' may result in an unaligned pointer value [-Waddress-of-packed-member]
../src/bmpio.c:187:32: warning: taking address of packed member 'bmpih' of class or structure 'BMP_HEADER' may result in an unaligned pointer value [-Waddress-of-packed-member]
../src/bmpio.c:188:31: warning: taking address of packed member 'bmpih' of class or structure 'BMP_HEADER' may result in an unaligned pointer value [-Waddress-of-packed-member]
../src/bmpio.c:189:36: warning: taking address of packed member 'bmpih' of class or structure 'BMP_HEADER' may result in an unaligned pointer value [-Waddress-of-packed-member]
../src/bmpio.c:190:30: warning: taking address of packed member 'bmpih' of class or structure 'BMP_HEADER' may result in an unaligned pointer value [-Waddress-of-packed-member]
../src/bmpio.c:191:30: warning: taking address of packed member 'bmpih' of class or structure 'BMP_HEADER' may result in an unaligned pointer value [-Waddress-of-packed-member]
../src/bmpio.c:610:5: warning: taking address of packed member 'bmpih' of class or structure 'BMP_HEADER' may result in an unaligned pointer value [-Waddress-of-packed-member]
../src/bmpio.c:611:5: warning: taking address of packed member 'bmpih' of class or structure 'BMP_HEADER' may result in an unaligned pointer value [-Waddress-of-packed-member]
../src/bmpio.c:612:5: warning: taking address of packed member 'bmpih' of class or structure 'BMP_HEADER' may result in an unaligned pointer value [-Waddress-of-packed-member]
../src/bmpio.c:613:5: warning: taking address of packed member 'bmpih' of class or structure 'BMP_HEADER' may result in an unaligned pointer value [-Waddress-of-packed-member]
../src/bmpio.c:614:5: warning: taking address of packed member 'bmpih' of class or structure 'BMP_HEADER' may result in an unaligned pointer value [-Waddress-of-packed-member]
../src/bmpio.c:615:5: warning: taking address of packed member 'bmpih' of class or structure 'BMP_HEADER' may result in an unaligned pointer value [-Waddress-of-packed-member]
../src/bmpio.c:616:5: warning: taking address of packed member 'bmpih' of class or structure 'BMP_HEADER' may result in an unaligned pointer value [-Waddress-of-packed-member]
../src/bmpio.c:617:5: warning: taking address of packed member 'bmpih' of class or structure 'BMP_HEADER' may result in an unaligned pointer value [-Waddress-of-packed-member]
../src/bmpio.c:618:5: warning: taking address of packed member 'bmpih' of class or structure 'BMP_HEADER' may result in an unaligned pointer value [-Waddress-of-packed-member]
../src/bmpio.c:619:5: warning: taking address of packed member 'bmpih' of class or structure 'BMP_HEADER' may result in an unaligned pointer value [-Waddress-of-packed-member]
../src/scale2.c:257:28: warning: floating-point comparison is always false; constant cannot be represented exactly in type 'float' [-Wliteral-range]
../prog/partition_reg.c:75:56: warning: implicit conversion from 'double' to 'l_int32' (aka 'int') changes value from 0.4 to 0 [-Wliteral-conversion]

Fix issue #750 and two other warnings which might even be classified as bugs.

This fixes a bug which is reported by the clang compiler on macOS:

      CC       partition_reg.o
    prog/partition_reg.c:75:56: warning: implicit conversion from 'double' to 'l_int32' (aka 'int') changes value from 0.4 to 0 [-Wliteral-conversion]
       75 |     TestPartition(rp, "test8.jpg", L_SORT_BY_AREA, 20, 0.4, "test2.pdf",
          |     ~~~~~~~~~~~~~                                      ^~~

Signed-off-by: Stefan Weil <[email protected]>
This fixes a bug reported by the clang compiler on macOS:

      CC       scale2.lo
    src/scale2.c:257:28: warning: floating-point comparison is always false; constant cannot be represented exactly in type 'float' [-Wliteral-range]
      257 |     } else if (scalefactor == 0.16667) {
          |                ~~~~~~~~~~~ ^  ~~~~~~~

Signed-off-by: Stefan Weil <[email protected]>
This fixes warnings from the clang compiler:

../src/bmpio.c:169:37: warning: taking address of packed member 'bmpih' of class or structure 'BMP_HEADER' may result in an unaligned pointer value [-Waddress-of-packed-member]
  169 |     compression = convertOnBigEnd32(bmpih->biCompression);
      |                                     ^~~~~
../src/bmpio.c:147:17: note: expanded from macro 'bmpih'
  147 | #define bmpih (&bmph->bmpih)
      |                 ^~~~~~~~~~~
../src/bmpio.c:186:31: warning: taking address of packed member 'bmpih' of class or structure 'BMP_HEADER' may result in an unaligned pointer value [-Waddress-of-packed-member]
  186 |     width = convertOnBigEnd32(bmpih->biWidth);
      |                               ^~~~~
../src/bmpio.c:147:17: note: expanded from macro 'bmpih'
  147 | #define bmpih (&bmph->bmpih)
      |                 ^~~~~~~~~~~
[...]

Signed-off-by: Stefan Weil <[email protected]>
@DanBloomberg DanBloomberg merged commit 681f4a3 into DanBloomberg:master Oct 14, 2024
11 checks passed
@DanBloomberg
Copy link
Owner

That was a bad bug you fixed in TestPartition() !

Good to know that floating pt constants that are not marked 'f' are represented internally as doubles, causing problems for comparison with float variables.

Thanks for fixing the longstanding 'address of packed member' problem.

@stweil stweil deleted the fix_warnings branch October 14, 2024 05:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants