Tue Dec 2 11:21:00 GMT 2014
-----BEGIN PGP SIGNED MESSAGE-----
I'm having the following, interesting problem using Newlib's sscanf().
Trying to read an IP address from a string with the following code
uint8_t a, b, c, d;
// This function returns a pointer to the
// string that represents the IP address
get_str( &str );
res = sscanf( str, "%" SCNu8 ".%" SCNu8 ".%" SCNu8 ".%" SCNu8,
&a, &b, &c, &d );
The thing is that *str, i.e. the address value that is stored in the
*str pointer, seems to be corrupted by sscanf().
Dumping the memory shows that the variables a, b, c and d are located
first in memory (stack area growing downwards) - let's say at byte
addresses 10, 11, 12 and 13. After that, the 4-byte pointer *str is
placed at address 14 to 17.
Before the call of sscanf(), *str has a value of 0xa14af968. After the
call to sscanf(), the value is 0xa14af900, meaning that the least
significant byte of the value, which is located at byte address 14
(little endian), is overwritten by sscanf(). The bytes at addresses 10
to 13 represent the correct numbers of the scanned IP address string.
I'm running a bare metal ARM Cortex-M4 based microcontroller, using
the compiler toolchain 2014q2 from here:
This includes GCC 4.8.4 and a Newlib snapshot from 2013-10-16 (at
least the changelog says so).
Now do you think this is a problem in Newlib or am I doing something
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
-----END PGP SIGNATURE-----
More information about the Newlib