...
Code Block | ||||
---|---|---|---|---|
| ||||
char* name; /* initialized externally */ char filename[128]; sprintf(filename, "%s.txt", name); /* open filename * / |
However, since because the sprintf()
function makes no guarantees regarding the length of the string generated, a sufficiently-long string in name
could generate a buffer overflow.
...
Code Block | ||||
---|---|---|---|---|
| ||||
char* name; /* initialized externally */
char filename[128];
snprintf(filename, sizeof( filename), "%s.txt", name);
/* open filename * /
|
...