From: Christos Zoulas Date: Sat, 11 Aug 2018 12:17:37 +0000 (+0000) Subject: PR/25: cbiedl: Avoid strength underflow. X-Git-Tag: FILE5_35~51 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b54c273435c873b1446730c1d2c609bece2c2f22;p=file PR/25: cbiedl: Avoid strength underflow. --- diff --git a/src/apprentice.c b/src/apprentice.c index 45cf2a9f..4d8a3dee 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.276 2018/08/01 10:18:02 christos Exp $") +FILE_RCSID("@(#)$File: apprentice.c,v 1.277 2018/08/11 12:17:37 christos Exp $") #endif /* lint */ #include "magic.h" @@ -841,7 +841,8 @@ private size_t apprentice_magic_strength(const struct magic *m) { #define MULT 10U - size_t ts, v, val = 2 * MULT; /* baseline strength */ + size_t ts, v; + ssize_t val = 2 * MULT; /* baseline strength */ switch (m->type) { case FILE_DEFAULT: /* make sure this sorts last */ @@ -947,9 +948,6 @@ apprentice_magic_strength(const struct magic *m) abort(); } - if (val == 0) /* ensure we only return 0 for FILE_DEFAULT */ - val = 1; - switch (m->factor_op) { case FILE_FACTOR_OP_NONE: break; @@ -969,6 +967,9 @@ apprentice_magic_strength(const struct magic *m) abort(); } + if (val <= 0) /* ensure we only return 0 for FILE_DEFAULT */ + val = 1; + /* * Magic entries with no description get a bonus because they depend * on subsequent magic entries to print something.