From: Christos Zoulas Date: Mon, 27 Jul 2015 09:12:32 +0000 (+0000) Subject: PR/470: Fix undefined behaviors. X-Git-Tag: FILE5_25~31 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=cd85f48ca55f220d3c55adb761f7ad3aabf86d10;p=file PR/470: Fix undefined behaviors. --- diff --git a/src/apprentice.c b/src/apprentice.c index 4b44515f..27ed39c6 100644 --- a/src/apprentice.c +++ b/src/apprentice.c @@ -32,7 +32,7 @@ #include "file.h" #ifndef lint -FILE_RCSID("@(#)$File: apprentice.c,v 1.232 2015/04/09 20:01:40 christos Exp $") +FILE_RCSID("@(#)$File: apprentice.c,v 1.233 2015/06/10 00:57:41 christos Exp $") #endif /* lint */ #include "magic.h" @@ -1348,8 +1348,9 @@ apprentice_load(struct magic_set *ms, const char *fn, int action) } i = set_text_binary(ms, mset[j].me, mset[j].count, i); } - qsort(mset[j].me, mset[j].count, sizeof(*mset[j].me), - apprentice_sort); + if (mset[j].me) + qsort(mset[j].me, mset[j].count, sizeof(*mset[j].me), + apprentice_sort); /* * Make sure that any level 0 "default" line is last @@ -3209,9 +3210,10 @@ file_pstring_length_size(const struct magic *m) } } protected size_t -file_pstring_get_length(const struct magic *m, const char *s) +file_pstring_get_length(const struct magic *m, const char *ss) { size_t len = 0; + const unsigned char *s = (const unsigned char *)ss; switch (m->str_flags & PSTRING_LEN) { case PSTRING_1_LE: