From f2dbe6685d414826efe5485d7e0fb416d4c61aee Mon Sep 17 00:00:00 2001 From: smatz Date: Sun, 31 Aug 2008 17:34:03 +0000 Subject: (svn r14204) -Fix (r7475): when determining length of a string with limited size, first check if we are not out of bounds already --- src/string_func.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/string_func.h b/src/string_func.h index 0a6ff6d28..1453170ad 100644 --- a/src/string_func.h +++ b/src/string_func.h @@ -48,7 +48,7 @@ static inline bool StrEmpty(const char *s) { return s == NULL || s[0] == '\0'; } static inline size_t ttd_strnlen(const char *str, size_t maxlen) { const char *t; - for (t = str; *t != '\0' && (size_t)(t - str) < maxlen; t++) {} + for (t = str; (size_t)(t - str) < maxlen && *t != '\0'; t++) {} return t - str; } -- cgit v1.2.3-70-g09d2