[En-Nut-Discussion] sscanf bug or feature ? %hx

ml mludwig at adc-elektronik.de
Wed Feb 6 19:32:34 CET 2008


Hi 

a problem with sscanf. When using %hx i see that it isn´t working and it
overwrites memory

example

void test(void) {
  unsigned short int ibcc;
  char          s1[]  = "41";
  sscanf(s1,"%2hx",&ibcc);
}

after sscanf s1 is destroyed showing "4("and ibcc contains 0 

i see that getf.c doesn´t check the h modifier. function allways returns int
or long so memory is overwriten
when using a char or short int.



i changed nut/crt/getf.c
to use h modifier 
and give back a pointer to char 
for this i have to introduce an new flag CF_SHORT (MSB in flags seems to be
free for this)
so now it works correct. 

i don´t know if anyone is interested in this or how to contribute this minor
change. 

Martin



-- 
View this message in context: http://www.nabble.com/sscanf--bug-or-feature----hx-tp15309888p15309888.html
Sent from the MicroControllers - Ethernut mailing list archive at Nabble.com.




More information about the En-Nut-Discussion mailing list