]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
a more robust check on the outcome of `regexec` and a more clean design
authorMario Di Raimondo <mario.diraimondo@gmail.com>
Mon, 15 Sep 2014 07:17:43 +0000 (09:17 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 15 Sep 2014 07:22:28 +0000 (09:22 +0200)
src/epggrab/module/opentv.c

index 75b8a0139651f7d86b61e6c9a2c198412ef7edd6..3554dfa0516e9a56c27a61c476b29215d694c426 100644 (file)
@@ -361,7 +361,7 @@ opentv_parse_event_section
       if (ev.summary) {
         regmatch_t match[4];
         char buf[1024];
-        int i;
+        int i,size;
 
         /* Parse Series/Episode */
         for (i = 0; i < ARRAY_SIZE(_opentv_se_num_patterns); i++) {
@@ -387,9 +387,10 @@ opentv_parse_event_section
 
         /* Parse Subtitle */
         for (i = 0; i < ARRAY_SIZE(_opentv_subtitle_patterns); i++) {
-          if (!regexec(_opentv_subtitle_pregs+i, ev.summary, 2, match, 0) && match[1].rm_eo - match[1].rm_so <= sizeof(buf) - 1) {
-            memcpy(buf, ev.summary + match[1].rm_so, match[1].rm_eo - match[1].rm_so);
-            buf[match[1].rm_eo - match[1].rm_so] = '\0';
+          if (!regexec(_opentv_subtitle_pregs+i, ev.summary, 2, match, 0) && match[1].rm_so != -1) {
+            size = MIN(match[1].rm_eo - match[1].rm_so, sizeof(buf) - 1);
+            memcpy(buf, ev.summary + match[1].rm_so, size);
+            buf[size] = '\0';
             tvhdebug("opentv", "  extract from summary subtitle %s", buf);
             save |= epg_episode_set_subtitle(ee, buf, lang, src);
             break; /* skip other patterns */