Forum

fscanf evilness

Discuss programming topics for the various GPL'd game engine sources.

Moderator: InsideQC Admins

fscanf evilness

Postby revelator » Tue Jul 05, 2011 10:30 am

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 :)
User avatar
revelator
 
Posts: 2567
Joined: Thu Jan 24, 2008 12:04 pm
Location: inside tha debugger

Return to Engine Programming

Who is online

Users browsing this forum: No registered users and 1 guest