for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
text[i] = ' ';
- memcpy (text, cl.levelname, strlen(cl.levelname));
+ // LordHavoc: added min() to prevent overflow
+ memcpy (text, cl.levelname, min(strlen(cl.levelname), SAVEGAME_COMMENT_LENGTH));
sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
memcpy (text+22, kills, strlen(kills));
-// convert space to _ to make stdio happy
+ // convert space to _ to make stdio happy
+ // LordHavoc: convert control characters to _ as well
for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
- if (text[i] == ' ')
+ if (text[i] <= ' ')
text[i] = '_';
text[SAVEGAME_COMMENT_LENGTH] = '\0';
}