[SDL] [HELP] SDL Segmentation

David Olofson david at olofson.net
Sun Jan 8 14:27:12 PST 2006


(This is not SDL related, but anyway...)

On Sunday 08 January 2006 20:07, Ivan wrote:
[...]
> 	char string[255];
[...]
> 	while(fgets(string,255,fin)!=NULL){

fgets() writes a NUL byte *after* the last byte read, so this will 
segfault if the file is longer than 254 bytes.

As a general rule when dealing with the string functions of the C 
library: Be very careful with those NUL terminators and buffer size 
limits...


//David Olofson - Programmer, Composer, Open Source Advocate

.-------  http://olofson.net - Games, SDL examples  -------.
|        http://zeespace.net - 2.5D rendering engine       |
|       http://audiality.org - Music/audio engine          |
|     http://eel.olofson.net - Real time scripting         |
'--  http://www.reologica.se - Rheology instrumentation  --'




More information about the SDL mailing list