Skip to content

Commit aa6ba77

Browse files
H1GHGuYsbabic
authored andcommitted
Fix coverity reports (#304621, #304620)
Comparisons against MAX_SAFE_INT were done in the int domain, rather than the source domain.
1 parent c418636 commit aa6ba77

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

core/semver.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ strcut (char *str, int begin, int len) {
4949
size_t l;
5050
l = strlen(str);
5151

52-
if((int)l < 0 || (int)l > MAX_SAFE_INT) return -1;
52+
if(l > (size_t)MAX_SAFE_INT) return -1;
5353

5454
if (len < 0) len = l - begin + 1;
5555
if (begin + len > (int)l) len = l - begin;
@@ -88,14 +88,17 @@ binary_comparison (int x, int y) {
8888

8989
static int
9090
parse_int (const char *s) {
91-
int valid, num;
91+
int valid;
92+
long int num;
9293
valid = has_valid_chars(s, NUMBERS);
9394
if (valid == 0) return -1;
9495

9596
num = strtol(s, NULL, 10);
9697
if (num > MAX_SAFE_INT) return -1;
98+
/* Shouldn't happen because '-' is a delimiter! */
99+
if (num < 0) return -1;
97100

98-
return num;
101+
return (int)num;
99102
}
100103

101104
/*

0 commit comments

Comments
 (0)