Undefined behaviour causing problems on AVR32

Bradley Smith bradsmith at debian.org
Wed Apr 8 12:03:55 CEST 2009


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.

(This is with the Debian packaged version gmp-4.2.4+dfsg, which is what
the patch has been created against).

Regards,
Bradley Smith

-- 
Bradley Smith                                     brad at brad-smith.co.uk
Debian GNU/Linux Developer                         bradsmith at debian.org
GPG: 0xC718D347       D201 7274 2FE1 A92A C45C EFAB 8F70 629A C718 D347
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: gmp-4.2.4-fix-undefined-behaviour.diff.txt
URL: <http://gmplib.org/list-archives/gmp-bugs/attachments/20090408/725ccf30/attachment.txt>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://gmplib.org/list-archives/gmp-bugs/attachments/20090408/725ccf30/attachment.bin>


More information about the gmp-bugs mailing list