fscanf evilness
Moderator: InsideQC Admins
1 post
• Page 1 of 1
fscanf evilness
quake is littered with fscanf and as a certain comment inside the source points out its pure evil, so what can we do about it.
one way is changing things to use fgets and sscanf.
fgets to make sure the buffer doesnt overflow by checking buffersize.
or simply keep fscanf and do it like this.
say you have a buffer of size 10
fscanf (buffer, %9s, whatever); will newer overflow since the size is 9 + terminator = 10
you can also use sizeof(buffer) if youre not sure about its size (pointer or otherwise).
old members probably allready know this so look away
one way is changing things to use fgets and sscanf.
fgets to make sure the buffer doesnt overflow by checking buffersize.
or simply keep fscanf and do it like this.
say you have a buffer of size 10
fscanf (buffer, %9s, whatever); will newer overflow since the size is 9 + terminator = 10
you can also use sizeof(buffer) if youre not sure about its size (pointer or otherwise).
old members probably allready know this so look away
-

revelator - Posts: 2567
- Joined: Thu Jan 24, 2008 12:04 pm
- Location: inside tha debugger
1 post
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest