gcc -fanalyzer

marco.bodrato at tutanota.com marco.bodrato at tutanota.com
Sat Sep 16 19:01:24 CEST 2023


Ciao,

gcc complains about missing call to 'va_end' in scanf/doscan.c and printf/doprnt.c .

man stdarg on my Debian reads: "Each  invocation of va_copy() must be matched by a corresponding invocation of va_end() in the same function."
So that probably gcc is right. I assume we never noticed, because probably va_end is a noop,
But, we may want to correct it anyway.

Correcting scanf/doscan.c is quite easy, I'd suggest:

~/src/gmp$ hg diff scanf/doscan.c
diff -r 8225bdfc499f scanf/doscan.c
--- a/scanf/doscan.c    Tue Sep 05 18:32:26 2023 +0200
+++ b/scanf/doscan.c    Sat Sep 16 18:40:28 2023 +0200
@@ -761,6 +761,7 @@
     }
 
  done:
+  va_end (ap);
   (*__gmp_free_func) (alloc_fmt, alloc_fmt_size);
   return fields;
}
~/src/gmp$

On the printf/doprnt.c side, I'm not sure.
There is a "va_copy (ap" at the beginning, so we can va_end before returning.
Each loop starts with a "va_copy (this_ap" and can end with a corresponding va_end.
But last_ap is va_copy-ed again and again; should we insert a va_end before each new copy?

I attach a possible patch for printf/doprnt.c .

Ĝis,
m
-------------- next part --------------
A non-text attachment was scrubbed...
Name: va.diff
Type: text/x-patch
Size: 1197 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-devel/attachments/20230916/24da1c34/attachment.bin>


More information about the gmp-devel mailing list