summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristos Zoulas <christos@zoulas.com>2018-08-11 12:17:37 +0000
committerChristos Zoulas <christos@zoulas.com>2018-08-11 12:17:37 +0000
commitb54c273435c873b1446730c1d2c609bece2c2f22 (patch)
tree759dfa39ee830c014288ef9ea57c08347facebbe /src
parenta0785d309b67bc4ad4e978ae6e10d22818461856 (diff)
downloadfile-git-b54c273435c873b1446730c1d2c609bece2c2f22.tar.gz
PR/25: cbiedl: Avoid strength underflow.
Diffstat (limited to 'src')
-rw-r--r--src/apprentice.c11
1 files changed, 6 insertions, 5 deletions
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.