Commit 70b9b841 by Krishna Ram Prakash R

Fixed bug while parsing INT64_MIN

parent 20302aa4
...@@ -128,8 +128,8 @@ int git__strntol64(int64_t *result, const char *nptr, size_t nptr_len, const cha ...@@ -128,8 +128,8 @@ int git__strntol64(int64_t *result, const char *nptr, size_t nptr_len, const cha
v = c - 'A' + 10; v = c - 'A' + 10;
if (v >= base) if (v >= base)
break; break;
nn = n*base + v; nn = n * base + (neg ? -v : v);
if (nn < n) if ((!neg && nn < n) || (neg && nn > n))
ovfl = 1; ovfl = 1;
n = nn; n = nn;
} }
...@@ -148,7 +148,7 @@ Return: ...@@ -148,7 +148,7 @@ Return:
return -1; return -1;
} }
*result = neg ? -n : n; *result = n;
return 0; return 0;
} }
......
...@@ -33,5 +33,13 @@ void test_core_strtol__int64(void) ...@@ -33,5 +33,13 @@ void test_core_strtol__int64(void)
cl_assert(i == 2147483657LL); cl_assert(i == 2147483657LL);
cl_git_pass(git__strtol64(&i, " -2147483657 ", NULL, 10)); cl_git_pass(git__strtol64(&i, " -2147483657 ", NULL, 10));
cl_assert(i == -2147483657LL); 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);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment