changeset 15382:ba07942279c5

strdup() of a NULL pointer, truckload of cola for me
author henry
date Mon, 09 May 2005 18:28:41 +0000
parents 3b9f6e52a4cb
children 0f4efec84983
files subreader.c
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/subreader.c	Mon May 09 18:00:37 2005 +0000
+++ b/subreader.c	Mon May 09 18:28:41 2005 +0000
@@ -1323,11 +1323,16 @@
     mp_msg(MSGT_SUBREADER, MSGL_V, "\n");
     
     for (i = 0; i < langcnt; i++) {
+	char *tmp;
+	
 	if (strcasecmp(languages[i], preferred_language) != 0) continue;
 	analyser = enca_analyser_alloc(languages[i]);
 	encoding = enca_analyse_const(analyser, buffer, buflen);
-	mp_msg(MSGT_SUBREADER, MSGL_INFO, "ENCA detected charset: %s\n", enca_charset_name(encoding.charset, ENCA_NAME_STYLE_ICONV));
-	detected_sub_cp = strdup(enca_charset_name(encoding.charset, ENCA_NAME_STYLE_ICONV));
+	tmp = enca_charset_name(encoding.charset, ENCA_NAME_STYLE_ICONV);
+	if (tmp) {
+	    detected_sub_cp = strdup(tmp);
+	    mp_msg(MSGT_SUBREADER, MSGL_INFO, "ENCA detected charset: %s\n", tmp);
+	}
 	enca_analyser_free(analyser);
     }
     
@@ -1335,7 +1340,10 @@
     free(buffer);
     rewind(fd);
 
-    if (!detected_sub_cp) detected_sub_cp = strdup(fallback);
+    if (!detected_sub_cp) {
+	detected_sub_cp = strdup(fallback);
+	mp_msg(MSGT_SUBREADER, MSGL_INFO, "ENCA detection failed: fallback to %s\n", fallback);
+    }
 
     return detected_sub_cp;
 }