| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | self-referencing sprintf() ? |
> Could someone tell me the `official' story here : > I am updating something for a microcontroller-based > application, and my cross-compiler is a supposedly ANSI C > platform. However, the existing source contains numerous > things like this : > char s[256]; > .... > sprintf((char *)&s,"password %s is incorrect (attempt -1.1%d)",&s,i); > .... > This particular compiler generates object code which is something like : > char s[256],*s2; > ... > s2=malloc[256]; > sprintf(s2,"password %s is incorrect (attempt -1.1%d)",&s,i); > strcpy((char *)&s,s2); > free(s2); > ... > The sprintf() function apparently contains a small buffer > string inside it to cope with a self-referencing argument > list. Is this standard C ? I think not.. but I want to be > sure. The behaviour of what is called "copying between overlapping objects" is "undefined" under ISO-C. It might work or it might not, but I wouldn't rely on it. ---* Origin: Unique Computing, Melbourne, Australia (3:632/348) SEEN-BY: 50/99 54/54 620/243 623/630 624/50 632/103 301 348 386 998 633/371 SEEN-BY: 633/379 634/384 635/301 502 503 541 544 636/100 639/100 711/401 409 SEEN-BY: 711/410 430 510 807 808 809 932 934 942 712/515 713/888 714/906 SEEN-BY: 800/1 7877/2809 @PATH: 632/103 348 635/503 50/99 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.