strdup() of a NULL pointer, truckload of cola for me

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@15383 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
henry 2005-05-09 18:28:41 +00:00
parent 6f68b43715
commit ce70204266
1 changed files with 11 additions and 3 deletions

View File

@ -1323,11 +1323,16 @@ void* guess_cp(FILE *fd, char *preferred_language, char *fallback)
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 @@ void* guess_cp(FILE *fd, char *preferred_language, char *fallback)
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;
}