somnisoft / smtp-client

SMTP Client Library in C
Creative Commons Zero v1.0 Universal
109 stars 31 forks source link

Warnings when compiling smtp.c with -O2 #1

Closed Mynock17 closed 5 years ago

Mynock17 commented 5 years ago

On Ubuntu 18.04 x86_64 witg gcc 7.3.0 I get this:

cc -O2 -DSMTP_OPENSSL smtp.c -c -o smtp.o

smtp.c: In function ‘smtp_mail’: smtp.c:1882:47: warning: ‘%0+5ld’ directive writing between 5 and 19 bytes into a region of size 15 [-Wformat-overflow=] "%s, %02d %s %d %02d:%02d:%02d %0+5ld", ^~ smtp.c:1882:16: note: directive argument in the range [-256204778801521500, 256204778801521500] "%s, %02d %s %d %02d:%02d:%02d %0+5ld", ^~~~~~~~~~ In file included from /usr/include/stdio.h:862:0, from /usr/include/openssl/bio.h:16, from smtp.c:54: /usr/include/x86_64-linux-gnu/bits/stdio2.h:33:10: note: ‘builtin___sprintf_chk’ output 23 or more bytes (assuming 37) into a destination of size 32 return builtin_sprintf_chk (s, USE_FORTIFY_LEVEL - 1, ^~~~~~~~~~~~~~ bos (s), fmt, __va_arg_pack ());

somnisoft commented 5 years ago

The compiler generates a false-positive warning. GCC documentation for -Wformat-overflow: 'While enabling optimization will in most cases improve the accuracy of the warning, it may also result in false positives.'

It appears to complain about the UTC offset and assumes it is unbounded. However, the offset is actually restricted to a maximum of 4 digits because earlier difftime() subtracts local and UTC time, and then computes the offset from that difference.

I committed a change [4f83bb8] to increase the buffer size which should silence the compiler warning.