[Privoxy-devel] cppcheck warnings in cgiedit.c

Lee ler762 at gmail.com
Fri Jan 4 20:58:11 UTC 2019


On 1/4/19, Fabian Keil <fk at fabiankeil.de> wrote:
> Lee <ler762 at gmail.com> wrote:
>
>> cppcheck spits out a bunch of warnings for cgiedit.c:
>>
>> [cgiedit.c:3196]: (warning) %lu in format string (no. 1) requires
>> 'unsigned long' but the argument type is 'signed long'.
>> [cgiedit.c:3317]: (warning) %lu in format string (no. 1) requires
>> 'unsigned long' but the argument type is 'signed long'.
>> [cgiedit.c:3440]: (warning) %lu in format string (no. 1) requires
>> 'unsigned long' but the argument type is 'signed long'.
>> [cgiedit.c:3551]: (warning) %lu in format string (no. 1) requires
>> 'unsigned long' but the argument type is 'signed long'.
>> [cgiedit.c:3673]: (warning) %lu in format string (no. 1) requires
>> 'unsigned long' but the argument type is 'signed long'.
>> [cgiedit.c:3836]: (warning) %lu in format string (no. 1) requires
>> 'unsigned long' but the argument type is 'signed long'.
>> [cgiedit.c:4025]: (warning) %lu in format string (no. 1) requires
>> 'unsigned long' but the argument type is 'signed long'.
>>
>> All the warnings are for '(long) time(NULL)' in snprintf using a '%lu'
>> format - eg:
>>    snprintf(target, sizeof(target), CGI_PREFIX
>> "edit-actions-list?foo=%lu&f=%u#l%u",
>>             (long) time(NULL), file->identifier, sectionid);
>>
>> If you wanted to get rid of the warnings, would it be better to change
>> for format to "%ld" or the type cast to "(unsigned long)"?
>
> I'd prefer a changed cast as the time can't be negative.

OK - I'll change the cast.

Just out of curiosity:
  $ echo | gcc -E -xc -include 'time.h' - | grep time_t
  typedef long __time_t;
  typedef long time_t;
time() can return a -1, so that's why time_t isn't unsigned long?

Thanks,
Lee


More information about the Privoxy-devel mailing list