mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-28 04:29:42 +00:00
Fixed bug while parsing INT64_MIN
This commit is contained in:
parent
a200dc9e1d
commit
1edbfa1ffe
@ -122,8 +122,8 @@ int git__strtol64(int64_t *result, const char *nptr, const char **endptr, int ba
|
||||
v = c - 'A' + 10;
|
||||
if (v >= base)
|
||||
break;
|
||||
nn = n*base + v;
|
||||
if (nn < n)
|
||||
nn = n * base + (neg ? -v : v);
|
||||
if ((!neg && nn < n) || (neg && nn > n))
|
||||
ovfl = 1;
|
||||
n = nn;
|
||||
}
|
||||
@ -142,7 +142,7 @@ Return:
|
||||
return -1;
|
||||
}
|
||||
|
||||
*result = neg ? -n : n;
|
||||
*result = n;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -33,5 +33,13 @@ void test_core_strtol__int64(void)
|
||||
cl_assert(i == 2147483657LL);
|
||||
cl_git_pass(git__strtol64(&i, " -2147483657 ", NULL, 10));
|
||||
cl_assert(i == -2147483657LL);
|
||||
cl_git_pass(git__strtol64(&i, " 9223372036854775807 ", NULL, 10));
|
||||
cl_assert(i == INT64_MAX);
|
||||
cl_git_pass(git__strtol64(&i, " -9223372036854775808 ", NULL, 10));
|
||||
cl_assert(i == INT64_MIN);
|
||||
cl_git_pass(git__strtol64(&i, " 0x7fffffffffffffff ", NULL, 16));
|
||||
cl_assert(i == INT64_MAX);
|
||||
cl_git_pass(git__strtol64(&i, " -0x8000000000000000 ", NULL, 16));
|
||||
cl_assert(i == INT64_MIN);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user