Package: gmp
Version: 2:4.2.4+dfsg-2
Severity: wishlist

In scanf/sscanffuns.c, the function 'scan' is defined as:

 static int scan (const char **sp, const char *fmt, void *p1, void *p2)

but is then casted to:

 int (*gmp_doscan_scan_t)  _PROTO ((void *, const char *, ...))

and used. Whilst most architectures seem to cope with this, it is
undefined behaviour and due to the way varargs are implemented on AVR32,
it causes segfaults/incorrect results.

I have attached a simple fix for this which simply changes 'scan' to use
varargs as in the gmp_doscan_scan_t prototype.

I have filed this as wishlist simply because AVR32 is not an official arch
yet, but rather just work in progress, but it otherwise would be serious
as it FTBFS because of it.

Note, I've also just sent this upstream.

Regards,
Bradley Smith

-- 
Bradley Smith                                     b...@brad-smith.co.uk
Debian GNU/Linux Developer                         bradsm...@debian.org
GPG: 0xC718D347       D201 7274 2FE1 A92A C45C EFAB 8F70 629A C718 D347
diff -Naur a/scanf/sscanffuns.c b/scanf/sscanffuns.c
--- a/scanf/sscanffuns.c        2007-08-30 19:31:41.000000000 +0100
+++ b/scanf/sscanffuns.c        2009-04-08 10:45:09.000000000 +0100
@@ -22,14 +22,27 @@
 along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
 
 #include <stdio.h>
+#include <stdarg.h>
 #include "gmp.h"
 #include "gmp-impl.h"
 
 
 static int
-scan (const char **sp, const char *fmt, void *p1, void *p2)
+scan (const char **sp, const char *fmt, ...)
 {
-  return sscanf (*sp, fmt, p1, p2);
+  va_list ap;
+  void *p1, *p2;
+  int ret;
+
+  va_start(ap, fmt);
+  p1 = va_arg(ap, void*);
+  p2 = va_arg(ap, void*);
+
+  ret = sscanf (*sp, fmt, p1, p2);
+
+  va_end(ap);
+
+  return ret;
 }
 
 static void

Attachment: signature.asc
Description: PGP signature

Reply via email to