diff options
author | mrwastl <mrwastl@users.sourceforge.net> | 2011-06-27 22:24:52 +0200 |
---|---|---|
committer | mrwastl <mrwastl@users.sourceforge.net> | 2011-06-27 22:24:52 +0200 |
commit | cba3ba244b99f54393f2faba57d2e0ec64c0f94f (patch) | |
tree | ace7465cc3b602a392f6ee78c0e8405312acbed5 | |
parent | 6da1c378c4d57b3bc5d345b5d56e515a831ddd1b (diff) | |
download | vdr-plugin-graphlcd-cba3ba244b99f54393f2faba57d2e0ec64c0f94f.tar.gz vdr-plugin-graphlcd-cba3ba244b99f54393f2faba57d2e0ec64c0f94f.tar.bz2 |
paranoia mode for strcmp
-rw-r--r-- | common.c | 16 | ||||
-rw-r--r-- | common.h | 1 | ||||
-rw-r--r-- | service.c | 13 |
3 files changed, 24 insertions, 6 deletions
@@ -3,6 +3,7 @@ #include <glcdskin/type.h> #include <vdr/plugin.h> +#include <string.h> #if APIVERSNUM < 10503 #include <locale.h> @@ -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; +} @@ -1,2 +1,3 @@ GLCD::cType TimeType(time_t Time, const std::string &Format); GLCD::cType DurationType(int Index, const std::string &Format); +int ParanoiaStrcmp(const char *s1, const char *s2); @@ -12,6 +12,7 @@ #include <limits> #include "service.h" +#include "common.h" #include <vdr/plugin.h> @@ -269,9 +270,9 @@ bool cGraphLCDService::NeedsUpdate(uint64_t CurrentTime) if ( (currRTSData.rds_info != checkRTSData.rds_info) || (currRTSData.rds_pty != checkRTSData.rds_pty) || - (checkRTSData.rds_text && (strcmp(currRTSData.rds_text, checkRTSData.rds_text) != 0)) || - (checkRTSData.rds_title && (strcmp(currRTSData.rds_title, checkRTSData.rds_title) != 0)) || - (checkRTSData.rds_artist && (strcmp(currRTSData.rds_artist, checkRTSData.rds_artist) != 0)) + (ParanoiaStrcmp(currRTSData.rds_text, checkRTSData.rds_text) != 0) || + (ParanoiaStrcmp(currRTSData.rds_title, checkRTSData.rds_title) != 0) || + (ParanoiaStrcmp(currRTSData.rds_artist, checkRTSData.rds_artist) != 0) ) { currRTSData.rds_info = checkRTSData.rds_info; @@ -300,9 +301,9 @@ bool cGraphLCDService::NeedsUpdate(uint64_t CurrentTime) if (cPluginManager::CallFirstService("LcrService-v1.0", &checkLcrData)) { lcrActive = true; if ( - (((const char*)checkLcrData.destination) && (strcmp(currLcrData.destination, checkLcrData.destination) != 0)) || - (((const char*)checkLcrData.price) && (strcmp(currLcrData.price, checkLcrData.price) != 0)) || - (((const char*)checkLcrData.pulse) && (strcmp(currLcrData.pulse, checkLcrData.pulse) != 0)) + (ParanoiaStrcmp(currLcrData.destination, checkLcrData.destination) != 0) || + (ParanoiaStrcmp(currLcrData.price, checkLcrData.price) != 0) || + (ParanoiaStrcmp(currLcrData.pulse, checkLcrData.pulse) != 0) ) { currLcrData.destination = checkLcrData.destination; |