mirror of
https://github.com/curl/curl.git
synced 2026-08-26 12:03:37 +03:00
strparse: switch to curl_off_t as base data type
- add hex and octal parsers to the Curl_str_* family - make curlx_strtoofft use these parsers - remove all use of strtol() and strtoul() in library code - generally use Curl_str_* more than strtoofft, for stricter parsing - supports 64-bit universally, instead of 'long' which differs in size between platforms Extended the unit test 1664 to verify hex and octal parsing. Closes #16336
This commit is contained in:
parent
876db1070b
commit
b4538ec522
46 changed files with 538 additions and 497 deletions
|
|
@ -196,7 +196,7 @@ UNITTEST_START
|
|||
};
|
||||
printf("Curl_str_number\n");
|
||||
for(i = 0; nums[i]; i++) {
|
||||
size_t num;
|
||||
curl_off_t num;
|
||||
const char *line = nums[i];
|
||||
const char *orgline = line;
|
||||
int rc = Curl_str_number(&line, &num, 1235);
|
||||
|
|
@ -206,10 +206,10 @@ UNITTEST_START
|
|||
}
|
||||
|
||||
{
|
||||
/* SIZE_T_MAX is typically 18446744073709551615 */
|
||||
/* CURL_OFF_T is typically 9223372036854775807 */
|
||||
static const char *nums[] = {
|
||||
"9223372036854775808", /* 2^63 */
|
||||
"9223372036854775809", /* 2^63 + 1 */
|
||||
"9223372036854775807", /* 2^63 -1 */
|
||||
"9223372036854775808", /* 2^63 */
|
||||
"18446744073709551615", /* 2^64 - 1 */
|
||||
"18446744073709551616", /* 2^64 */
|
||||
"18446744073709551617", /* 2^64 + 1 */
|
||||
|
|
@ -217,11 +217,11 @@ UNITTEST_START
|
|||
};
|
||||
printf("Curl_str_number / max\n");
|
||||
for(i = 0; nums[i]; i++) {
|
||||
size_t num;
|
||||
curl_off_t num;
|
||||
const char *line = nums[i];
|
||||
const char *orgline = line;
|
||||
int rc = Curl_str_number(&line, &num, SIZE_T_MAX);
|
||||
printf("%u: (\"%s\") %d, [%zu] line %d\n",
|
||||
int rc = Curl_str_number(&line, &num, CURL_OFF_T_MAX);
|
||||
printf("%u: (\"%s\") %d, [%" CURL_FORMAT_CURL_OFF_T "] line %d\n",
|
||||
i, orgline, rc, num, (int)(line - orgline));
|
||||
}
|
||||
}
|
||||
|
|
@ -250,5 +250,95 @@ UNITTEST_START
|
|||
}
|
||||
}
|
||||
|
||||
{
|
||||
static const char *nums[] = {
|
||||
"1",
|
||||
"1000",
|
||||
"1234",
|
||||
"1235",
|
||||
"1236",
|
||||
"01234",
|
||||
"00000000000000000000000000001234",
|
||||
"0123 345",
|
||||
"0123O345",
|
||||
"-12",
|
||||
" 123",
|
||||
"",
|
||||
NULL
|
||||
};
|
||||
printf("Curl_str_hex\n");
|
||||
for(i = 0; nums[i]; i++) {
|
||||
curl_off_t num;
|
||||
const char *line = nums[i];
|
||||
const char *orgline = line;
|
||||
int rc = Curl_str_hex(&line, &num, 0x1235);
|
||||
printf("%u: (\"%s\") %d, [%u] line %d\n",
|
||||
i, orgline, rc, (int)num, (int)(line - orgline));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
static const char *nums[] = {
|
||||
"1",
|
||||
"1000",
|
||||
"1234",
|
||||
"1235",
|
||||
"1236",
|
||||
"01234",
|
||||
"00000000000000000000000000001234",
|
||||
"0123 345",
|
||||
"0123O345",
|
||||
"-12",
|
||||
" 123",
|
||||
"",
|
||||
NULL
|
||||
};
|
||||
printf("Curl_str_octal\n");
|
||||
for(i = 0; nums[i]; i++) {
|
||||
curl_off_t num;
|
||||
const char *line = nums[i];
|
||||
const char *orgline = line;
|
||||
int rc = Curl_str_octal(&line, &num, 01235);
|
||||
printf("%u: (\"%s\") %d, [%u] line %d\n",
|
||||
i, orgline, rc, (int)num, (int)(line - orgline));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
/* CURL_OFF_T is typically 2^63-1 */
|
||||
static const char *nums[] = {
|
||||
"777777777777777777777", /* 2^63 -1 */
|
||||
"1000000000000000000000", /* 2^63 */
|
||||
NULL
|
||||
};
|
||||
printf("Curl_str_octal / max\n");
|
||||
for(i = 0; nums[i]; i++) {
|
||||
curl_off_t num;
|
||||
const char *line = nums[i];
|
||||
const char *orgline = line;
|
||||
int rc = Curl_str_octal(&line, &num, CURL_OFF_T_MAX);
|
||||
printf("%u: (\"%s\") %d, [%" CURL_FORMAT_CURL_OFF_T "] line %d\n",
|
||||
i, orgline, rc, num, (int)(line - orgline));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
/* CURL_OFF_T is typically 2^63-1 */
|
||||
static const char *nums[] = {
|
||||
"7FFFFFFFFFFFFFFF", /* 2^63 -1 */
|
||||
"8000000000000000", /* 2^63 */
|
||||
NULL
|
||||
};
|
||||
printf("Curl_str_hex / max\n");
|
||||
for(i = 0; nums[i]; i++) {
|
||||
curl_off_t num;
|
||||
const char *line = nums[i];
|
||||
const char *orgline = line;
|
||||
int rc = Curl_str_hex(&line, &num, CURL_OFF_T_MAX);
|
||||
printf("%u: (\"%s\") %d, [%" CURL_FORMAT_CURL_OFF_T "] line %d\n",
|
||||
i, orgline, rc, num, (int)(line - orgline));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
UNITTEST_STOP
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue