[PATCH 1/5] warnings in canonicalize.c

Bruno Haible bruno@clisp.org
Fri Dec 25 00:44:46 GMT 2020


Paul Eggert wrote:
> > @@ -270,7 +270,7 @@
> >                 buf[n] = '\0';
> > 
> >                 char *extra_buf = extra_buffer.data;
> > -              idx_t end_idx;
> > +              idx_t end_idx = 0;
> >                 if (end_in_extra_buffer)
> >                   end_idx = end - extra_buf;
> >                 idx_t len = strlen (end);
> 
> This change isn't needed, since end_idx is used only when 
> end_in_extra_buffer is true.
> 
> Was the latter change put in only to pacify older GCC versions?

Yes.

> (I don't get a warning with GCC 10.2.)

Indeed, I don't see warnings in canonicalize-lgpl.c. But there are warnings
in gnulib's canonicalize.c:

gcc 9.3.0:

$ gcc -DHAVE_CONFIG_H -I. -I.. -Wall -g -O2 -c ./canonicalize.c                                    
./canonicalize.c: In function 'canonicalize_filename_mode_stk':
./canonicalize.c:337:16: warning: unused variable 'discard' [-Wunused-variable]
  337 |           char discard;
      |                ^~~~~~~
./canonicalize.c: In function 'canonicalize_filename_mode':
./canonicalize.c:400:33: warning: 'end_idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  400 |                 end = extra_buf + end_idx;
      |                       ~~~~~~~~~~^~~~~~~~~
./canonicalize.c:389:21: note: 'end_idx' was declared here
  389 |               idx_t end_idx;
      |                     ^~~~~~~

gcc 10.2.0:

$ gcc -DHAVE_CONFIG_H -I. -I.. -Wall -g -O2 -c ./canonicalize.c                                    
./canonicalize.c: In function 'canonicalize_filename_mode_stk':
./canonicalize.c:337:16: warning: unused variable 'discard' [-Wunused-variable]
  337 |           char discard;
      |                ^~~~~~~
...
./canonicalize.c:400:33: warning: 'end_idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
  400 |                 end = extra_buf + end_idx;
      |                       ~~~~~~~~~~^~~~~~~~~
./canonicalize.c:389:21: note: 'end_idx' was declared here
  389 |               idx_t end_idx;
      |                     ^~~~~~~

Bruno



More information about the Libc-alpha mailing list