wernsey / bitmap

A C module for manipulating bitmap/raster graphics
MIT No Attribution
69 stars 12 forks source link

Compiler warnings on macOS #4

Closed mitchcurtis closed 4 years ago

mitchcurtis commented 4 years ago

When building as part of a C++ project on macOS:

/usr/bin/gcc -O2 -Wall -Wextra -target x86_64-apple-macosx10.7-macho -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -pipe -fvisibility=default -fPIC -DNDEBUG -DQT_DEPRECATED_WARNINGS -DQT_CORE_LIB -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_QML_LIB -DQT_QMLTEST_LIB -DQT_TESTLIB_LIB -DQT_WIDGETS_LIB -DQT_QUICK_LIB -I/Users/mitch/dev/slate/app -I/Users/mitch/dev/slate/tests/shared -I/Users/mitch/dev/slate/lib/3rdparty -I/Users/mitch/dev/qt5-slate-fw/qtbase/include -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtCore -I/Users/mitch/dev/qt5-slate/qtbase/mkspecs/macx-clang -I/Users/mitch/dev/slate-qt5_slate_fw-Release/Release/test-app.99bdad93/qt.headers -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtCore/5.13.0 -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtCore/5.13.0/QtCore -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtGui -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtNetwork -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtQml -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtQml/5.13.0 -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtQml/5.13.0/QtQml -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtQuickTest -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtTest -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtWidgets -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtQuick -I/Users/mitch/dev/slate/lib -o /Users/mitch/dev/slate-qt5_slate_fw-Release/Release/test-app.99bdad93/1158f7fbc157be47/gif.c.o -c /Users/mitch/dev/slate/lib/3rdparty/bitmap/misc/gif.c /Users/mitch/dev/slate/lib/3rdparty/bitmap/misc/gif.c:198:54: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare] if(fread(palette, sizeof *palette, sgct, fp) != sgct) {


/Users/mitch/dev/slate/lib/3rdparty/bitmap/misc/gif.c:363:44: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare]
        if(fread(ct, sizeof *ct, slct, fp) != slct) {
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~
/Users/mitch/dev/slate/lib/3rdparty/bitmap/misc/gif.c:858:22: warning: comparison of integers of different signs: 'unsigned int' and 'int' [-Wsign-compare]
        for(q = 0; q < nc; q++) {
                   ~ ^ ~~
/Users/mitch/dev/slate/lib/3rdparty/bitmap/misc/gif.c:862:22: warning: comparison of integers of different signs: 'unsigned int' and 'int' [-Wsign-compare]
        for(q = 0; q < nc; q++) {
                   ~ ^ ~~
/Users/mitch/dev/slate/lib/3rdparty/bitmap/misc/gif.c:882:22: warning: comparison of integers of different signs: 'unsigned int' and 'int' [-Wsign-compare]
        for(q = 0; q < nc; q++) {
                   ~ ^ ~~
/Users/mitch/dev/slate/lib/3rdparty/bitmap/misc/gif.c:929:42: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare]
    if(fwrite(gct, sizeof *gct, sgct, f) != sgct) {
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~
6 warnings generated.
[...]
/usr/bin/gcc -O2 -Wall -Wextra -target x86_64-apple-macosx10.7-macho -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -pipe -fvisibility=default -fPIC -DNDEBUG -DQT_DEPRECATED_WARNINGS -DQT_CORE_LIB -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_QML_LIB -DQT_QMLTEST_LIB -DQT_TESTLIB_LIB -DQT_WIDGETS_LIB -DQT_QUICK_LIB -I/Users/mitch/dev/slate/app -I/Users/mitch/dev/slate/tests/shared -I/Users/mitch/dev/slate/lib/3rdparty -I/Users/mitch/dev/qt5-slate-fw/qtbase/include -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtCore -I/Users/mitch/dev/qt5-slate/qtbase/mkspecs/macx-clang -I/Users/mitch/dev/slate-qt5_slate_fw-Release/Release/test-app.99bdad93/qt.headers -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtCore/5.13.0 -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtCore/5.13.0/QtCore -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtGui -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtNetwork -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtQml -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtQml/5.13.0 -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtQml/5.13.0/QtQml -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtQuickTest -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtTest -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtWidgets -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtQuick -I/Users/mitch/dev/slate/lib -o /Users/mitch/dev/slate-qt5_slate_fw-Release/Release/test-app.99bdad93/7562038ad4e26393/bmp.c.o -c /Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c
/Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:439:26: warning: result of comparison of constant 255 with expression of type 'char' is always false [-Wtautological-constant-out-of-range-compare]
        else if(magic[0] == 0xFF && magic[1] == 0xD8)
                ~~~~~~~~ ^  ~~~~
/Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:439:46: warning: result of comparison of constant 216 with expression of type 'char' is always false [-Wtautological-constant-out-of-range-compare]
        else if(magic[0] == 0xFF && magic[1] == 0xD8)
                                    ~~~~~~~~ ^  ~~~~
/Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:443:26: warning: result of comparison of constant 137 with expression of type 'char' is always false [-Wtautological-constant-out-of-range-compare]
        else if(magic[0] == 0x89 && !memcmp(magic+1, "PNG", 3))
                ~~~~~~~~ ^  ~~~~
/Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:683:50: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare]
        if(rd.fread(data, 1, rs * b->h, rd.data) != rs * b->h) {
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~
/Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:1757:62: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare]
        if(rd.fread(palette, sizeof *palette, sgct, rd.data) != sgct) {
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~
/Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:1877:52: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare]
        if(rd.fread(ct, sizeof *ct, slct, rd.data) != slct) {
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~
/Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:2427:43: warning: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Wsign-compare]
        fwrite(gct, sizeof *gct, sgct, f) != sgct) {
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~~~
/Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:3549:27: warning: comparison of integers of different signs: 'int' and 'unsigned int' [-Wsign-compare]
            if(!mask || c != maskc)
                        ~ ^  ~~~~~
/Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:3636:46: warning: unused parameter 'dx' [-Wunused-parameter]
unsigned int bm_smp_outline(Bitmap *dst, int dx, int dy, Bitmap *src, int sx, int sy, unsigned int dest_color) {
                                             ^
/Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:3636:54: warning: unused parameter 'dy' [-Wunused-parameter]
unsigned int bm_smp_outline(Bitmap *dst, int dx, int dy, Bitmap *src, int sx, int sy, unsigned int dest_color) {
                                                     ^
/Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:3664:45: warning: unused parameter 'dx' [-Wunused-parameter]
unsigned int bm_smp_border(Bitmap *dst, int dx, int dy, Bitmap *src, int sx, int sy, unsigned int dest_color) {
                                            ^
/Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:3664:53: warning: unused parameter 'dy' [-Wunused-parameter]
unsigned int bm_smp_border(Bitmap *dst, int dx, int dy, Bitmap *src, int sx, int sy, unsigned int dest_color) {
                                                    ^
/Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:3696:45: warning: unused parameter 'dx' [-Wunused-parameter]
unsigned int bm_smp_binary(Bitmap *dst, int dx, int dy, Bitmap *src, int sx, int sy, unsigned int dest_color) {
                                            ^
/Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:3696:53: warning: unused parameter 'dy' [-Wunused-parameter]
unsigned int bm_smp_binary(Bitmap *dst, int dx, int dy, Bitmap *src, int sx, int sy, unsigned int dest_color) {
                                                    ^
/Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:3703:37: warning: unused parameter 'dst' [-Wunused-parameter]
unsigned int bm_smp_blend50(Bitmap *dst, int dx, int dy, Bitmap *src, int sx, int sy, unsigned int dest_color) {
                                    ^
/Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:3703:46: warning: unused parameter 'dx' [-Wunused-parameter]
unsigned int bm_smp_blend50(Bitmap *dst, int dx, int dy, Bitmap *src, int sx, int sy, unsigned int dest_color) {
                                             ^
/Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:3703:54: warning: unused parameter 'dy' [-Wunused-parameter]
unsigned int bm_smp_blend50(Bitmap *dst, int dx, int dy, Bitmap *src, int sx, int sy, unsigned int dest_color) {
                                                     ^
/Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:5537:18: warning: comparison of integers of different signs: 'int' and 'unsigned int' [-Wsign-compare]
    for(i = 0; i < npal; i++) {
               ~ ^ ~~~~
/Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:6034:32: warning: unused parameter 'font' [-Wunused-parameter]
static int xbmf_height(BmFont *font) {
                               ^
19 warnings generated.

Compiler version:

/usr/bin/gcc --version Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/c++/4.2.1 Apple LLVM version 10.0.0 (clang-1000.11.45.2) Target: x86_64-apple-darwin18.7.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

wernsey commented 4 years ago

Thank you for this. Those seem like easy fixes. I'll do something about it ASAP, but I don't know if it would be before the weekend.

wernsey commented 4 years ago

I just pushed a version that fixed the compiler warnings you listed. I don't have access to a macOS development environment, but I reproduced the warnings just fine on GCC on my dev machine

I also added -Wextra to the CFLAGS in the makefile so that these kinds of warnings don't happen in the future.

There are still some warnings related to variable 'h' might be clobbered by 'longjmp' that I will fix later, so I won't close this ticket yet.

mitchcurtis commented 4 years ago

I just tried out the new bmp.c on macOS, but got an error:

20:17:20: Running steps for project slate... compiling bmp.c [lib] compiling bmp.c [test-app] /usr/bin/gcc -O2 -Wall -Wextra -target x86_64-apple-macosx10.7-macho -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -F/Users/mitch/dev/qt5-slate-fw/qtbase/lib -pipe -fvisibility=default -fPIC -DNDEBUG -DQT_DEPRECATED_WARNINGS -DQT_CORE_LIB -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_QML_LIB -DQT_QMLTEST_LIB -DQT_TESTLIB_LIB -DQT_WIDGETS_LIB -DQT_QUICK_LIB -I/Users/mitch/dev/slate/app -I/Users/mitch/dev/slate/tests/shared -I/Users/mitch/dev/slate/lib/3rdparty -I/Users/mitch/dev/qt5-slate-fw/qtbase/include -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtCore -I/Users/mitch/dev/qt5-slate/qtbase/mkspecs/macx-clang -I/Users/mitch/dev/slate-qt5_slate_fw-Release/Release/test-app.99bdad93/qt.headers -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtCore/5.13.1 -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtCore/5.13.1/QtCore -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtGui -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtNetwork -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtQml -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtQml/5.13.1 -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtQml/5.13.1/QtQml -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtQuickTest -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtTest -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtWidgets -I/Users/mitch/dev/qt5-slate-fw/qtbase/include/QtQuick -I/Users/mitch/dev/slate/lib -o /Users/mitch/dev/slate-qt5_slate_fw-Release/Release/test-app.99bdad93/7562038ad4e26393/bmp.c.o -c /Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c /Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.c:69:20: error: static declaration of 'bm_last_error' follows non-static declaration static const char bm_last_error = "no error"; ^ /Users/mitch/dev/slate/lib/3rdparty/bitmap/bmp.h:68:20: note: previous declaration is here extern const char bm_last_error; ^ 1 error generated.

mitchcurtis commented 4 years ago

Thanks for fixing these by the way! :D

wernsey commented 4 years ago

Hi @mitchcurtis,

You need to get the latest version of bmp.h as well.

Among the recent changes, I changed the variable bm_last_error to be static within bmp.c and only expose it througn a new function bm_get_error() to make my API cleaner.

It seems you have a previous version of bmp.h where bm_last_error is still being exposed in the header.

mitchcurtis commented 4 years ago

Ah, sorry! I was looking at that one commit but I guess I missed some!

mitchcurtis commented 4 years ago

I found some other warnings, but I dunno if this is how you want them fixed:

diff --git a/lib/3rdparty/bitmap/misc/gif.c b/lib/3rdparty/bitmap/misc/gif.c
index 12ce389..ea44588 100644
--- a/lib/3rdparty/bitmap/misc/gif.c
+++ b/lib/3rdparty/bitmap/misc/gif.c
@@ -120,7 +120,7 @@ static GIF *gif_load_fp(FILE *fp) {
     GIF_FILE file;

     /* From the packed fields in the logical screen descriptor */
-    int gct, col_res, sort_flag, sgct;
+    size_t gct, col_res, sort_flag, sgct;
     float aspect_ratio;

     struct gif_triplet *palette = NULL;
@@ -203,7 +203,7 @@ static GIF *gif_load_fp(FILE *fp) {

         output(stdout, "Global Color Table: %d entries\n", sgct);
         if(gif_verbose > 1) {
-            int i;
+            size_t i;
             for(i = 0; i < sgct; i++) {
                 output(stdout, " %3d: %02X %02X %02X\n", i, palette[i].r, palette[i].g, palette[i].b);
             }
@@ -325,7 +325,7 @@ static int gif_read_image(FILE *fp, GIF_FILE *file, struct gif_triplet *ct, int
     GIF_ID gif_id;

     /* Packed fields in the Image Descriptor */
-    int lct, intl, sort, slct;
+    size_t lct, intl, sort, slct;

     memset(&gce, 0, sizeof gce);

@@ -368,7 +368,7 @@ static int gif_read_image(FILE *fp, GIF_FILE *file, struct gif_triplet *ct, int

         output(stdout, "Local Color Table: %d entries\n", slct);
         if(gif_verbose > 1) {
-            int i;
+            size_t i;
             for(i = 0; i < slct; i++) {
                 output(stdout, " %3d: %02X %02X %02X\n", i, ct[i].r, ct[i].g, ct[i].b);
             }
@@ -832,7 +832,7 @@ static int gif_save_fp(GIF *g, FILE *f) {
     GIF_FILE file;
     GIF_GCE gce;
     GIF_ID gif_id;
-    int nc, sgct, bg;
+    unsigned int nc, sgct, bg;
     struct gif_triplet gct[256];
     unsigned char code_size = 0x08;
     Bitmap *b = g->n > 0 ? g->frames[0].image : NULL;
@@ -971,7 +971,7 @@ static int gif_save_fp(GIF *g, FILE *f) {
         int x, y, p = 0;
         for(y = 0; y < b->h; y++) {
             for(x = 0; x < b->w; x++) {
-                int i;
+                unsigned int i;
                 int c = bm_get(b, x, y);
                 i = bsrch_palette_lookup(gct, c, 0, nc - 1);
                 /* At this point in time, the color MUST be in the palette */

I can submit it as a pull request if you want?

wernsey commented 4 years ago

Hi @mitchcurtis , Yes, please submit a pull request. Thanks