I've recently become aware of a warning message that can be output
when compiling info:

$ make
make  all-am
make[1]: Entering directory '/home/g/src/texinfo/GIT/info'
gcc -DHAVE_CONFIG_H -I. -I..  -I.. -I../gnulib/lib -I../gnulib/lib 
-DLOCALEDIR=\"/usr/local/share/locale\" -DINFODIR=\"/usr/local/share/info\" 
-DINFODIR2=\"/usr/local/share/info\" -DSYSCONFDIR=\"/usr/local/etc\" 
-DPKGDATADIR=\"/usr/local/share/texinfo\"   -g -O2 -MT filesys.o -MD -MP -MF 
.deps/filesys.Tpo -c -o filesys.o filesys.c
In file included from /usr/include/features.h:502,
                 from /usr/include/assert.h:35,
                 from ../config.h:2680,
                 from ../system.h:23,
                 from info.h:24,
                 from filesys.c:20:
In function ‘read’,
    inlined from ‘filesys_read_info_file’ at filesys.c:347:12:
/usr/include/x86_64-linux-gnu/bits/unistd.h:28:10: warning: ‘__read_alias’ 
specified size 18446744073709551614 exceeds maximum object size 
9223372036854775807 [-Wstringop-overflow=]
   28 |   return __glibc_fortify (read, __nbytes, sizeof (char),
      |          ^~~~~~~~~~~~~~~
/usr/include/x86_64-linux-gnu/bits/unistd-decl.h: In function 
‘filesys_read_info_file’:
/usr/include/x86_64-linux-gnu/bits/unistd-decl.h:29:16: note: in a call to 
function ‘__read_alias’ declared with attribute ‘access (write_only, 2, 3)’
   29 | extern ssize_t __REDIRECT_FORTIFY (__read_alias, (int __fd, void *__buf,
      |                ^~~~~~~~~~~~~~~~~~
mv -f .deps/filesys.Tpo .deps/filesys.Po
gcc  -g -O2   -o ginfo configfiles.o dir.o display.o dribble.o echo-area.o 
filesys.o footnotes.o indices.o info.o infodoc.o infokey.o infomap.o infopath.o 
m-x.o man.o nodemenu.o nodes.o run-external.o scan.o search.o session.o 
session-cmd.o signals.o tag.o terminal.o tilde.o util.o variables.o window.o 
doc.o ../gnulib/lib/libgnu.a -ltinfo         
make[1]: Leaving directory '/home/g/src/texinfo/GIT/info'


This warning is issued with the current git master as well as Texinfo 7.2.
The warning message from gcc is very obscure but appears to be about
the following line of code:

      if ((read (descriptor, contents, read_file_size)) != read_file_size)

It does not like the third argument to 'read'.

I found reverting the following change got rid of the warning:

Author: Patrice Dumas <[email protected]>
Date:   2024-10-10 11:56:24 +0200

    * info/filesys.c (filesys_read_info_file): convert to ssize_t to use
    as read return value an not to size_t and convert to size_t later on.
    Do not cast finfo->st_size to (long), leave it as off_t and convert to
    either size_t or ssize_t depending on how the file is read.  Add
    comments to mark conversion from unsigned to signed.
    
    * info/filesys.c (convert_eols): use size_t in argument an as return
    type.

I found changing a single line would also get rid of the warning:

--- a/info/filesys.c
+++ b/info/filesys.c
@@ -330,7 +330,7 @@ filesys_read_info_file (char *pathname, size_t *filesize,
   else
     {
       int descriptor;
-      ssize_t read_file_size = stat_fsize;
+      size_t read_file_size = stat_fsize;
 
       *is_compressed = 0;
       descriptor = open (pathname, O_RDONLY | O_BINARY, 0666);


So does adding a check that read_file_size is positive:

--- a/info/filesys.c
+++ b/info/filesys.c
@@ -344,7 +344,8 @@ filesys_read_info_file (char *pathname, size_t *filesize,
 
       /* Try to read the contents of this file. */
       contents = xmalloc (1 + read_file_size);
-      if ((read (descriptor, contents, read_file_size)) != read_file_size)
+      if (read_file_size > 0
+        && (read (descriptor, contents, read_file_size)) != read_file_size)
         {
          filesys_error_number = errno;
          close (descriptor);

The third argument to 'read' is declared as size_t so perhaps the warning
is triggered by passing in a value of type ssize_t that could potentially
be negative.

I'll try to commit a fix to add such a check.

I haven't understand fully all the reasons for the changes to types in
this code.  I expect this problem is a hangover from people deciding to
convert from unsigned integer types to signed integer types or vice versa.

(In commit 219bed49caf262a (2012-11-17), types were changed from long (signed)
to size_t (unsigned).  This was further changed in the commit above.)



Reply via email to