snprintf warning with ubuntu + c89 + clang + cmake #927
Closed
Description
This is taken from #926 (comment)
Seeing the warnings below with c89 (and iso9899:199409) + clang + cmake on Ubuntu. The equivalent Mac build is fine. Also there is no issue when built with configure, so the issue must lie with zconf.h
and/or the clang commandline.
Adding -DNO_vsnprintf
to CFLAGS
sorts this issue. Fix needed is to get CMakesList.txt
to do the equivalent test that configure
does for vsnprintf
.
The cmake function check_c_source_compiles looks like a candidate for this change.
$ rm -fr build ; CFLAGS=" -std=c89" cmake -S . -B build -D CMAKE_BUILD_TYPE=Release -D CMAKE_C_COMPILER=clang -D ZLIB_BUILD_EXAMPLES=off
-- The C compiler identification is Clang 16.0.6
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of off64_t
-- Check size of off64_t - done
-- Looking for fseeko
-- Looking for fseeko - found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Looking for stdarg.h
-- Looking for stdarg.h - found
-- Configuring done (2.1s)
-- Generating done (0.0s)
-- Build files have been written to: /home/paul/git/zlib/build
$ cmake --build build
[ 3%] Building C object CMakeFiles/zlib.dir/adler32.c.o
[ 6%] Building C object CMakeFiles/zlib.dir/compress.c.o
[ 9%] Building C object CMakeFiles/zlib.dir/crc32.c.o
[ 12%] Building C object CMakeFiles/zlib.dir/deflate.c.o
[ 15%] Building C object CMakeFiles/zlib.dir/gzclose.c.o
[ 18%] Building C object CMakeFiles/zlib.dir/gzlib.c.o
/home/paul/git/zlib/gzlib.c:204:15: warning: implicitly declaring library function 'snprintf' with type 'int (char *, unsigned long, const char *, ...)' [-Wimplicit-function-declaration]
(void)snprintf(state->path, len + 1, "%s", (const char *)path);
^
/home/paul/git/zlib/gzlib.c:204:15: note: include the header <stdio.h> or explicitly provide a declaration for 'snprintf'
1 warning generated.
[ 21%] Building C object CMakeFiles/zlib.dir/gzread.c.o
[ 25%] Building C object CMakeFiles/zlib.dir/gzwrite.c.o
/home/paul/git/zlib/gzwrite.c:407:11: warning: implicitly declaring library function 'vsnprintf' with type 'int (char *, unsigned long, const char *, struct __va_list_tag *)' [-Wimplicit-function-declaration]
len = vsnprintf(next, state->size, format, va);
^
/home/paul/git/zlib/gzwrite.c:407:11: note: include the header <stdio.h> or explicitly provide a declaration for 'vsnprintf'
1 warning generated.
[ 28%] Building C object CMakeFiles/zlib.dir/inflate.c.o
[ 31%] Building C object CMakeFiles/zlib.dir/infback.c.o
[ 34%] Building C object CMakeFiles/zlib.dir/inftrees.c.o
[ 37%] Building C object CMakeFiles/zlib.dir/inffast.c.o
[ 40%] Building C object CMakeFiles/zlib.dir/trees.c.o
[ 43%] Building C object CMakeFiles/zlib.dir/uncompr.c.o
[ 46%] Building C object CMakeFiles/zlib.dir/zutil.c.o
[ 50%] Linking C shared library libz.so
[ 50%] Built target zlib
[ 53%] Building C object CMakeFiles/zlibstatic.dir/adler32.c.o
[ 56%] Building C object CMakeFiles/zlibstatic.dir/compress.c.o
[ 59%] Building C object CMakeFiles/zlibstatic.dir/crc32.c.o
[ 62%] Building C object CMakeFiles/zlibstatic.dir/deflate.c.o
[ 65%] Building C object CMakeFiles/zlibstatic.dir/gzclose.c.o
[ 68%] Building C object CMakeFiles/zlibstatic.dir/gzlib.c.o
/home/paul/git/zlib/gzlib.c:204:15: warning: implicitly declaring library function 'snprintf' with type 'int (char *, unsigned long, const char *, ...)' [-Wimplicit-function-declaration]
(void)snprintf(state->path, len + 1, "%s", (const char *)path);
^
/home/paul/git/zlib/gzlib.c:204:15: note: include the header <stdio.h> or explicitly provide a declaration for 'snprintf'
1 warning generated.
[ 71%] Building C object CMakeFiles/zlibstatic.dir/gzread.c.o
[ 75%] Building C object CMakeFiles/zlibstatic.dir/gzwrite.c.o
/home/paul/git/zlib/gzwrite.c:407:11: warning: implicitly declaring library function 'vsnprintf' with type 'int (char *, unsigned long, const char *, struct __va_list_tag *)' [-Wimplicit-function-declaration]
len = vsnprintf(next, state->size, format, va);
^
/home/paul/git/zlib/gzwrite.c:407:11: note: include the header <stdio.h> or explicitly provide a declaration for 'vsnprintf'
1 warning generated.
[ 78%] Building C object CMakeFiles/zlibstatic.dir/inflate.c.o
[ 81%] Building C object CMakeFiles/zlibstatic.dir/infback.c.o
[ 84%] Building C object CMakeFiles/zlibstatic.dir/inftrees.c.o
[ 87%] Building C object CMakeFiles/zlibstatic.dir/inffast.c.o
[ 90%] Building C object CMakeFiles/zlibstatic.dir/trees.c.o
[ 93%] Building C object CMakeFiles/zlibstatic.dir/uncompr.c.o
[ 96%] Building C object CMakeFiles/zlibstatic.dir/zutil.c.o
[100%] Linking C static library libz.a
[100%] Built target zlibstatic
Metadata
Assignees
Labels
No labels