roelj / inklingreader

A GNU/Linux-friendly version of the Wacom Inkling SketchManager.
GNU General Public License v3.0
50 stars 16 forks source link

New warnings with clang on OS X 10.7.5 #18

Closed su-v closed 10 years ago

su-v commented 10 years ago

When compiling current master (@5a16b6e14a5445de597f5a1f8d02e91186f48cdf) on OS X 10.7.5 with clang (based on LLVM 3.1svn), there's still a warning related to malloc:

  CC       src/gui/mainwindow.o
src/gui/mainwindow.c:108:21: warning: implicitly declaring C library function 'malloc' with type 'void *(unsigned long)'
      int* number = malloc (sizeof (int));
                    ^
src/gui/mainwindow.c:108:21: note: please include the header <stdlib.h> or explicitly provide a declaration for 'malloc'
1 warning generated.

This diff makes the warning go away (same was used in other places where 'malloc.h' is included):

diff --git a/src/gui/mainwindow.c b/src/gui/mainwindow.c
index 645a97e..fc9a1af 100644
--- a/src/gui/mainwindow.c
+++ b/src/gui/mainwindow.c
@@ -22,6 +22,7 @@
 #include "../datatypes/configuration.h"
 #include <gtk/gtk.h>

+#include <stdlib.h> 
 #ifndef __APPLE__
 #include <malloc.h>
 #endif

and another (new) warning later on:

  CC       src/high/configuration.o
src/high/configuration.c:107:19: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
      while (read = getline (&line, &line_len, file) != -1)
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/high/configuration.c:107:19: note: place parentheses around the assignment to silence this warning
      while (read = getline (&line, &line_len, file) != -1)
                  ^
             (                                            )
src/high/configuration.c:107:19: note: use '==' to turn this assignment into an equality comparison
      while (read = getline (&line, &line_len, file) != -1)
                  ^
                  ==
1 warning generated.

Note: I used this sequence of commands, with an otherwise unmodified checkout of master:

$ touch AUTHORS NEWS
$ autoreconf -i
$ CC=clang ./configure --prefix="$HOME/.local"
$ make
roelj commented 10 years ago

Does stdlib.h provide the malloc function on OS X? If so, I'll take extra care to make sure this is handled correctly in the future.

I guess the

while (read = getline (&line, &line_len, file) != -1)
warning can be resolved by not using this shorthand syntax.

I'll change that and provide the fix.

roelj commented 10 years ago

Could you try again and see if the warnings/errors are resolved now?

su-v commented 10 years ago

AFAICT all resolved now - no more warnings with 3f3c82081db89de99676038f8bd7ab2fc039488f:

$ git status
# On branch master
nothing to commit (working directory clean)
$ git pull
remote: Counting objects: 18, done.
remote: Compressing objects: 100% (18/18), done.
remote: Total 18 (delta 4), reused 0 (delta 0)
Unpacking objects: 100% (18/18), done.
From https://github.com/roelj/inklingreader
   5a16b6e..3f3c820  master     -> origin/master
Updating 5a16b6e..3f3c820
Fast-forward
 src/converters/svg.c     |  217 ++++++++++++++++++++++-----------------------
 src/gui/mainwindow.c     |    2 +
 src/high/configuration.c |    2 +-
 src/main.c               |    1 -
 src/parsers/wpi.c        |   20 ++--
 5 files changed, 119 insertions(+), 123 deletions(-)
$ touch AUTHORS NEWS
$ autoreconf -i
$ CC=CLANG ./configure --prefix=$HOME/.local
checking for a BSD-compatible install... /Volumes/magenta/mp-trunk/quartz/bin/ginstall -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /Volumes/magenta/mp-trunk/quartz/bin/gmkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports nested variables... (cached) yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking for gcc... CLANG
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether CLANG accepts -g... yes
checking for CLANG option to accept ISO C89... none needed
checking whether CLANG understands -c and -o together... yes
checking for style of include used by make... GNU
checking dependency style of CLANG... gcc3
checking for pkg-config... /Volumes/magenta/mp-trunk/quartz/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for INKLINGREADER... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating Makefile
config.status: executing depfiles commands
$ make
  CC       src/main.o
  CC       src/gui/mainwindow.o
  CC       src/gui/mainwindow_sig.o
  CC       src/converters/svg.o
  CC       src/converters/png.o
  CC       src/converters/json.o
  CC       src/converters/pdf.o
  CC       src/parsers/wpi.o
  CC       src/high/conversion.o
  CC       src/high/configuration.o
  CCLD     inklingreader
$ ./inklingreader --version
Version: 0.6
$ 
roelj commented 10 years ago

That looks really clean. Thank you for reporting the issues and providing a solution for the malloc.h replacement with stdlib.h.