Open th1nk3r-ing opened 1 year ago
The test code is :
int main(void)
{
const char *pStr = "0xb400007896140dc0";
uint64_t out = strtoull(pStr, NULL, 0);
uint64_t out1 = strtoll(pStr, NULL, 0);
printf("[%s %d] pStr:[%s], strtoll:[0x%"PRIx64"], strtoull:[0x%"PRIx64"]",
__func__, __LINE__, pStr, out1, out);
return 0;
}
result : [main 13] pStr:[0xb400007896140dc0], strtoll:[0x7fffffffffffffff], strtoull:[0xb400007896140dc0]
It would cause overflow when the highest bit of the address is 1. So, we should using
strtoull
, notstrtoll