From cba3ba244b99f54393f2faba57d2e0ec64c0f94f Mon Sep 17 00:00:00 2001 From: mrwastl Date: Mon, 27 Jun 2011 22:24:52 +0200 Subject: paranoia mode for strcmp --- common.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'common.c') diff --git a/common.c b/common.c index e6c2113..439540d 100644 --- a/common.c +++ b/common.c @@ -3,6 +3,7 @@ #include #include +#include #if APIVERSNUM < 10503 #include @@ -141,3 +142,18 @@ GLCD::cType DurationType(int Index, const std::string &Format) } return false; } + +int ParanoiaStrcmp(const char *s1, const char *s2) +{ + if (! s1 || ! s2) + return -1; + + // s1 must be under 'our' control (and thus valid), s2 may be a string w/ unexpected content + size_t n = strlen(s1); + + int rv = strncmp(s1, s2, n); + if (rv == 0) + return (s2[n] == '\0') ? 0 : -1; + else + return rv; +} -- cgit v1.2.3