[Privoxy-devel] cppcheck warnings in cgiedit.c
    Fabian Keil 
    fk at fabiankeil.de
       
    Sat Jan  5 15:36:18 UTC 2019
    
    
  
Lee <ler762 at gmail.com> wrote:
> 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?
Yes. I overlooked that time() can return -1.
It probably doesn't matter, though.
Fabian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <https://lists.privoxy.org/pipermail/privoxy-devel/attachments/20190105/d028fc0f/attachment.bin>
    
    
More information about the Privoxy-devel
mailing list