summaryrefslogtreecommitdiff
path: root/openttd.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-10-21 23:31:34 +0000
committerDarkvater <darkvater@openttd.org>2006-10-21 23:31:34 +0000
commitee27bb497c0790d86da6025fa48034f01f36d6e0 (patch)
treebbd2a7ac7e0c3b558bf638e1779108ced158cb6a /openttd.c
parent7f36a980c70d2444a68af5046e47c0313d67b2ef (diff)
downloadopenttd-ee27bb497c0790d86da6025fa48034f01f36d6e0.tar.xz
(svn r6884) -Codechange: Add strict bounds checking in string formatting system.
The last parameter should point to the end of the buffer (eg lastof(buf)) Courtesy of Tron.
Diffstat (limited to 'openttd.c')
-rw-r--r--openttd.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/openttd.c b/openttd.c
index ba7cddcd5..cd28d9697 100644
--- a/openttd.c
+++ b/openttd.c
@@ -17,6 +17,7 @@
#include "functions.h"
#include "mixer.h"
#include "spritecache.h"
+#include "strings.h"
#include "gfx.h"
#include "gfxinit.h"
#include "gui.h"
@@ -878,16 +879,17 @@ static void DoAutosave(void)
if (_patches.keep_all_autosave && _local_player != PLAYER_SPECTATOR) {
const Player *p = GetPlayer(_local_player);
- char *s;
- sprintf(buf, "%s%s", _path.autosave_dir, PATHSEP);
+ char* s = buf;
+
+ s += snprintf(buf, lengthof(buf), "%s%s", _path.autosave_dir, PATHSEP);
SetDParam(0, p->name_1);
SetDParam(1, p->name_2);
SetDParam(2, _date);
- s = GetString(buf + strlen(_path.autosave_dir) + strlen(PATHSEP), STR_4004);
- strcpy(s, ".sav");
+ s = GetString(s, STR_4004, lastof(buf));
+ strecpy(s, ".sav", lastof(buf));
} else { /* generate a savegame name and number according to _patches.max_num_autosaves */
- sprintf(buf, "%s%sautosave%d.sav", _path.autosave_dir, PATHSEP, _autosave_ctr);
+ snprintf(buf, lengthof(buf), "%s%sautosave%d.sav", _path.autosave_dir, PATHSEP, _autosave_ctr);
_autosave_ctr++;
if (_autosave_ctr >= _patches.max_num_autosaves) {