summaryrefslogtreecommitdiff
path: root/string.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 /string.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 'string.c')
-rw-r--r--string.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/string.c b/string.c
index a0e6b42a6..50625c2fb 100644
--- a/string.c
+++ b/string.c
@@ -1,6 +1,8 @@
/* $Id$ */
#include "stdafx.h"
+#include "openttd.h"
+#include "functions.h"
#include "string.h"
#include <stdarg.h>
@@ -26,7 +28,7 @@ void ttd_strlcpy(char *dst, const char *src, size_t size)
char* strecat(char* dst, const char* src, const char* last)
{
- assert(last == NULL || dst <= last);
+ assert(dst <= last);
for (; *dst != '\0'; ++dst)
if (dst == last) return dst;
for (; *src != '\0' && dst != last; ++dst, ++src) *dst = *src;
@@ -37,9 +39,14 @@ char* strecat(char* dst, const char* src, const char* last)
char* strecpy(char* dst, const char* src, const char* last)
{
- assert(last == NULL || dst <= last);
+ assert(dst <= last);
for (; *src != '\0' && dst != last; ++dst, ++src) *dst = *src;
*dst = '\0';
+#if 0
+ if (dst == last && *src != '\0') {
+ error("String too long for destination buffer");
+ }
+#endif
return dst;
}