On Mon May 8 2023 16:47:56 deloptes via tde-devels wrote: > I did some debugging and pinpointed sscanf. It is not reading strings > properly. > Do you have any idea what could be the reason for this? > > see attached for an example where the format and the string are from the > code and configuration respectively %as is looking for a float so let's ignore that. If we switch back to %s it's looking for a string which would be great except no memory has been allocated for the strings. The attached works with both gcc and clang but the important thing to remember is NEVER NEVER NEVER use scanf or any variant thereof. https://dwheeler.com/secure-programs/Secure-Programs-HOWTO/dangers-c.html --Mike
/* sscanf example */ #include <stdio.h> int main (void) { char sentence []="interpreter usb 0x04b8 0x0142 /usr/lib/esci/libesci-interpreter-perfection-v330 /usr/share/esci/esfwad.bin"; unsigned int vendor; unsigned int product; char library[1024]; char firmware[1024]; sscanf (sentence, "%*s %*s %x %x %s %s", &vendor, &product, library, firmware); printf ("vendor %x\n", vendor); printf ("product %x\n", product); printf ("library %s\n", library); printf ("firmware %s\n", firmware); return 0; }
____________________________________________________ tde-devels mailing list -- devels@xxxxxxxxxxxxxxxxxx To unsubscribe send an email to devels-leave@xxxxxxxxxxxxxxxxxx Web mail archive available at https://mail.trinitydesktop.org/mailman3/hyperkitty/list/devels@xxxxxxxxxxxxxxxxxx