mirror of
https://git.gnunet.org/libmicrohttpd.git
synced 2026-10-01 04:03:18 +03:00
remove dead code converting hex number to size_t
This commit is contained in:
4 files changed
+4
-765
No files matched your search
@@ -1,3 +1,7 @@
|
||||
Sat Mar 25 20:58:24 CET 2017
|
||||
Remove dead MHD_strx_to_sizet-functions and associated
|
||||
test cases from code. -CG
|
||||
|
||||
Sat Mar 25 20:40:10 CET 2017
|
||||
Allow chunk size > 16 MB (up to 2^64-1). Ignore
|
||||
chunk extensions instead of triggering an error.
|
||||
|
||||
@@ -453,95 +453,6 @@ MHD_str_to_uint64_n_ (const char * str,
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert hexadecimal US-ASCII digits in string to number in size_t.
|
||||
* Conversion stopped at first non-digit character.
|
||||
*
|
||||
* @param str string to convert
|
||||
* @param[out] out_val pointer to size_t to store result of conversion
|
||||
* @return non-zero number of characters processed on succeed,
|
||||
* zero if no digit is found, resulting value is larger
|
||||
* then possible to store in size_t or @a out_val is NULL
|
||||
*/
|
||||
size_t
|
||||
MHD_strx_to_sizet_ (const char *str,
|
||||
size_t *out_val)
|
||||
{
|
||||
const char * const start = str;
|
||||
size_t res;
|
||||
int digit;
|
||||
|
||||
if (!str || !out_val)
|
||||
return 0;
|
||||
|
||||
res = 0;
|
||||
digit = toxdigitvalue (*str);
|
||||
while (digit >= 0)
|
||||
{
|
||||
if ( (res < (SIZE_MAX / 16)) ||
|
||||
( (res == (SIZE_MAX / 16)) &&
|
||||
((size_t)digit <= (SIZE_MAX % 16)) ) )
|
||||
{
|
||||
res *= 16;
|
||||
res += digit;
|
||||
}
|
||||
else
|
||||
return 0;
|
||||
str++;
|
||||
digit = toxdigitvalue (*str);
|
||||
}
|
||||
|
||||
if (str - start > 0)
|
||||
*out_val = res;
|
||||
return str - start;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert not more then @a maxlen hexadecimal US-ASCII digits in string
|
||||
* to number in size_t.
|
||||
* Conversion stopped at first non-digit character or after @a maxlen
|
||||
* digits.
|
||||
*
|
||||
* @param str string to convert
|
||||
* @param maxlen maximum number of characters to process
|
||||
* @param[out] out_val pointer to size_t to store result of conversion
|
||||
* @return non-zero number of characters processed on succeed,
|
||||
* zero if no digit is found, resulting value is larger
|
||||
* then possible to store in size_t or @a out_val is NULL
|
||||
*/
|
||||
size_t
|
||||
MHD_strx_to_sizet_n_ (const char * str,
|
||||
size_t maxlen,
|
||||
size_t *out_val)
|
||||
{
|
||||
size_t i;
|
||||
size_t res;
|
||||
int digit;
|
||||
if (!str || !out_val)
|
||||
return 0;
|
||||
|
||||
res = 0;
|
||||
i = 0;
|
||||
while ( (i < maxlen) &&
|
||||
((digit = toxdigitvalue (str[i])) >= 0) )
|
||||
{
|
||||
if ( (res > (SIZE_MAX / 16)) ||
|
||||
( (res == (SIZE_MAX / 16)) &&
|
||||
((size_t)digit > (SIZE_MAX % 16)) ) )
|
||||
return 0;
|
||||
|
||||
res *= 16;
|
||||
res += digit;
|
||||
i++;
|
||||
}
|
||||
|
||||
if (i)
|
||||
*out_val = res;
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert hexadecimal US-ASCII digits in string to number in uint32_t.
|
||||
* Conversion stopped at first non-digit character.
|
||||
|
||||
@@ -105,38 +105,6 @@ MHD_str_to_uint64_n_ (const char * str,
|
||||
uint64_t * out_val);
|
||||
|
||||
|
||||
/**
|
||||
* Convert hexadecimal US-ASCII digits in string to number in size_t.
|
||||
* Conversion stopped at first non-digit character.
|
||||
* @param str string to convert
|
||||
* @param out_val pointer to size_t to store result of conversion
|
||||
* @return non-zero number of characters processed on succeed,
|
||||
* zero if no digit is found, resulting value is larger
|
||||
* then possible to store in size_t or @a out_val is NULL
|
||||
*/
|
||||
size_t
|
||||
MHD_strx_to_sizet_ (const char * str,
|
||||
size_t * out_val);
|
||||
|
||||
|
||||
/**
|
||||
* Convert not more then @a maxlen hexadecimal US-ASCII digits in string
|
||||
* to number in size_t.
|
||||
* Conversion stopped at first non-digit character or after @a maxlen
|
||||
* digits.
|
||||
* @param str string to convert
|
||||
* @param maxlen maximum number of characters to process
|
||||
* @param out_val pointer to size_t to store result of conversion
|
||||
* @return non-zero number of characters processed on succeed,
|
||||
* zero if no digit is found, resulting value is larger
|
||||
* then possible to store in size_t or @a out_val is NULL
|
||||
*/
|
||||
size_t
|
||||
MHD_strx_to_sizet_n_ (const char * str,
|
||||
size_t maxlen,
|
||||
size_t * out_val);
|
||||
|
||||
|
||||
/**
|
||||
* Convert hexadecimal US-ASCII digits in string to number in uint32_t.
|
||||
* Conversion stopped at first non-digit character.
|
||||
|
||||
@@ -1496,523 +1496,6 @@ int check_str_to_uint64_n_no_val(void)
|
||||
}
|
||||
|
||||
|
||||
int check_strx_to_sizet_valid(void)
|
||||
{
|
||||
size_t t_failed = 0;
|
||||
size_t i, j;
|
||||
static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]);
|
||||
int c_failed[n_checks];
|
||||
|
||||
memset(c_failed, 0, sizeof(c_failed));
|
||||
|
||||
for(j = 0; j < locale_name_count; j++)
|
||||
{
|
||||
set_test_locale(j); /* setlocale() can be slow! */
|
||||
for(i = 0; i < n_checks; i++)
|
||||
{
|
||||
size_t rv;
|
||||
size_t rs;
|
||||
const struct str_with_value * const t = xdstrs_w_values + i;
|
||||
|
||||
#if SIZE_MAX != UINT64_MAX
|
||||
if (t->val > SIZE_MAX)
|
||||
continue; /* number is too high for this function */
|
||||
#endif /* SIZE_MAX != UINT64_MAX */
|
||||
|
||||
if (c_failed[i])
|
||||
continue; /* skip already failed checks */
|
||||
|
||||
if (t->str.len < t->num_of_digt)
|
||||
{
|
||||
fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
|
||||
" to be less or equal to str.len (%u).\n",
|
||||
(unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len);
|
||||
return -1;
|
||||
}
|
||||
rv = 1458532; /* some random value */
|
||||
rs = MHD_strx_to_sizet_(t->str.str, &rv);
|
||||
if (rs != t->num_of_digt)
|
||||
{
|
||||
t_failed++;
|
||||
c_failed[i] = !0;
|
||||
fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting %d."
|
||||
" Locale: %s\n", n_prnt(t->str.str), (uint64_t)rv, (intptr_t)rs, (int)t->num_of_digt, get_current_locale_str());
|
||||
}
|
||||
if (rv != t->val)
|
||||
{
|
||||
t_failed++;
|
||||
c_failed[i] = !0;
|
||||
fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") converted string to value 0x%" PRIX64 ","
|
||||
" while expecting result 0x%" PRIX64 ". Locale: %s\n", n_prnt(t->str.str), (uint64_t)rv, (uint64_t)rv,
|
||||
t->val, get_current_locale_str());
|
||||
}
|
||||
if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
|
||||
printf("PASSED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") == %" PRIuPTR "\n",
|
||||
n_prnt(t->str.str), (uint64_t)rv, rs);
|
||||
}
|
||||
}
|
||||
return t_failed;
|
||||
}
|
||||
|
||||
|
||||
int check_strx_to_sizet_all_chars(void)
|
||||
{
|
||||
static const size_t n_checks = 256; /* from 0 to 255 */
|
||||
int c_failed[n_checks];
|
||||
size_t t_failed = 0;
|
||||
size_t j;
|
||||
|
||||
memset(c_failed, 0, sizeof(c_failed));
|
||||
|
||||
for(j = 0; j < locale_name_count; j++)
|
||||
{
|
||||
unsigned int c;
|
||||
size_t test_val;
|
||||
|
||||
set_test_locale(j); /* setlocale() can be slow! */
|
||||
for(c = 0; c < n_checks; c++)
|
||||
{
|
||||
static const size_t rnd_val = 234234;
|
||||
size_t rs;
|
||||
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') ||(c >= 'a' && c <= 'f'))
|
||||
continue; /* skip xdigits */
|
||||
for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val)
|
||||
{
|
||||
char test_str[] = "0123";
|
||||
size_t rv = test_val;
|
||||
|
||||
test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
|
||||
rs = MHD_strx_to_sizet_(test_str, &rv);
|
||||
if (rs != 0)
|
||||
{
|
||||
t_failed++;
|
||||
c_failed[c] = !0;
|
||||
fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero."
|
||||
" Locale: %s\n", n_prnt(test_str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
|
||||
}
|
||||
else if (rv != test_val)
|
||||
{
|
||||
t_failed++;
|
||||
c_failed[c] = !0;
|
||||
fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", &ret_val) modified value of ret_val"
|
||||
" (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n",
|
||||
n_prnt(test_str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str());
|
||||
}
|
||||
}
|
||||
if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c])
|
||||
{
|
||||
char test_str[] = "0123";
|
||||
test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
|
||||
|
||||
printf("PASSED: MHD_strx_to_sizet_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
|
||||
n_prnt(test_str));
|
||||
}
|
||||
}
|
||||
}
|
||||
return t_failed;
|
||||
}
|
||||
|
||||
|
||||
int check_strx_to_sizet_overflow(void)
|
||||
{
|
||||
size_t t_failed = 0;
|
||||
size_t i, j;
|
||||
static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]);
|
||||
#if SIZE_MAX != UINT64_MAX
|
||||
static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]) +
|
||||
sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]);
|
||||
#else /* SIZE_MAX == UINT64_MAX */
|
||||
static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]);
|
||||
#endif /* SIZE_MAX == UINT64_MAX */
|
||||
int c_failed[n_checks];
|
||||
|
||||
memset(c_failed, 0, sizeof(c_failed));
|
||||
|
||||
for(j = 0; j < locale_name_count; j++)
|
||||
{
|
||||
set_test_locale(j); /* setlocale() can be slow! */
|
||||
for(i = 0; i < n_checks; i++)
|
||||
{
|
||||
size_t rs;
|
||||
static const size_t rnd_val = 74218431;
|
||||
size_t test_val;
|
||||
const char * str;
|
||||
if (i < n_checks1)
|
||||
{
|
||||
const struct str_with_len * const t = strx_ovflw + i;
|
||||
str = t->str;
|
||||
}
|
||||
#if SIZE_MAX != UINT64_MAX
|
||||
else
|
||||
{
|
||||
const struct str_with_value * const t = xdstrs_w_values + (i - n_checks1);
|
||||
if (t->val <= SIZE_MAX)
|
||||
continue; /* check only strings that should overflow size_t */
|
||||
str = t->str.str;
|
||||
}
|
||||
#else /* SIZE_MAX == UINT64_MAX */
|
||||
else
|
||||
continue; /* silent compiler warning */
|
||||
#endif /* SIZE_MAX == UINT64_MAX */
|
||||
|
||||
|
||||
for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
|
||||
{
|
||||
size_t rv = test_val;
|
||||
|
||||
rs = MHD_strx_to_sizet_(str, &rv);
|
||||
if (rs != 0)
|
||||
{
|
||||
t_failed++;
|
||||
c_failed[i] = !0;
|
||||
fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero."
|
||||
" Locale: %s\n", n_prnt(str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
|
||||
}
|
||||
else if (rv != test_val)
|
||||
{
|
||||
t_failed++;
|
||||
c_failed[i] = !0;
|
||||
fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", &ret_val) modified value of ret_val"
|
||||
" (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n",
|
||||
n_prnt(str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str());
|
||||
}
|
||||
}
|
||||
if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
|
||||
printf("PASSED: MHD_strx_to_sizet_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
|
||||
n_prnt(str));
|
||||
}
|
||||
}
|
||||
return t_failed;
|
||||
}
|
||||
|
||||
|
||||
int check_strx_to_sizet_no_val(void)
|
||||
{
|
||||
size_t t_failed = 0;
|
||||
size_t i, j;
|
||||
static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]);
|
||||
int c_failed[n_checks];
|
||||
|
||||
memset(c_failed, 0, sizeof(c_failed));
|
||||
|
||||
for(j = 0; j < locale_name_count; j++)
|
||||
{
|
||||
set_test_locale(j); /* setlocale() can be slow! */
|
||||
for(i = 0; i < n_checks; i++)
|
||||
{
|
||||
size_t rs;
|
||||
const struct str_with_len * const t = str_no_num + i;
|
||||
static const size_t rnd_val = 74218431;
|
||||
size_t test_val;
|
||||
|
||||
for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
|
||||
{
|
||||
size_t rv = test_val;
|
||||
|
||||
rs = MHD_strx_to_sizet_(t->str, &rv);
|
||||
if (rs != 0)
|
||||
{
|
||||
t_failed++;
|
||||
c_failed[i] = !0;
|
||||
fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", ->0x%" PRIX64 ") returned %" PRIuPTR ", while expecting zero."
|
||||
" Locale: %s\n", n_prnt(t->str), (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
|
||||
}
|
||||
else if (rv != test_val)
|
||||
{
|
||||
t_failed++;
|
||||
c_failed[i] = !0;
|
||||
fprintf(stderr, "FAILED: MHD_strx_to_sizet_(\"%s\", &ret_val) modified value of ret_val"
|
||||
" (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 "). Locale: %s\n",
|
||||
n_prnt(t->str), (uint64_t)test_val, (uint64_t)rv, get_current_locale_str());
|
||||
}
|
||||
}
|
||||
if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
|
||||
printf("PASSED: MHD_strx_to_sizet_(\"%s\", &ret_val) == 0, value of ret_val is unmodified\n",
|
||||
n_prnt(t->str));
|
||||
}
|
||||
}
|
||||
return t_failed;
|
||||
}
|
||||
|
||||
|
||||
int check_strx_to_sizet_n_valid(void)
|
||||
{
|
||||
size_t t_failed = 0;
|
||||
size_t i, j;
|
||||
static const size_t n_checks = sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]);
|
||||
int c_failed[n_checks];
|
||||
|
||||
memset(c_failed, 0, sizeof(c_failed));
|
||||
|
||||
for(j = 0; j < locale_name_count; j++)
|
||||
{
|
||||
set_test_locale(j); /* setlocale() can be slow! */
|
||||
for(i = 0; i < n_checks; i++)
|
||||
{
|
||||
size_t rv = 2352932; /* some random value */
|
||||
size_t rs = 0;
|
||||
size_t len;
|
||||
const struct str_with_value * const t = xdstrs_w_values + i;
|
||||
|
||||
#if SIZE_MAX != UINT64_MAX
|
||||
if (t->val > SIZE_MAX)
|
||||
continue; /* number is too high for this function */
|
||||
#endif /* SIZE_MAX != UINT64_MAX */
|
||||
|
||||
if (t->str.len < t->num_of_digt)
|
||||
{
|
||||
fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
|
||||
" to be less or equal to str.len (%u).\n",
|
||||
(unsigned int) i, (unsigned int) t->num_of_digt, (unsigned int) t->str.len);
|
||||
return -1;
|
||||
}
|
||||
for (len = t->num_of_digt; len <= t->str.len + 1 && !c_failed[i]; len++)
|
||||
{
|
||||
rs = MHD_strx_to_sizet_n_(t->str.str, len, &rv);
|
||||
if (rs != t->num_of_digt)
|
||||
{
|
||||
t_failed++;
|
||||
c_failed[i] = !0;
|
||||
fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
|
||||
" returned %" PRIuPTR ", while expecting %d. Locale: %s\n",
|
||||
n_prnt(t->str.str), (intptr_t)len, (uint64_t)rv, (intptr_t)rs,
|
||||
(int)t->num_of_digt, get_current_locale_str());
|
||||
}
|
||||
if (rv != t->val)
|
||||
{
|
||||
t_failed++;
|
||||
c_failed[i] = !0;
|
||||
fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
|
||||
" converted string to value 0x%" PRIX64 ", while expecting result 0x%" PRIX64
|
||||
". Locale: %s\n", n_prnt(t->str.str), (intptr_t)len, (uint64_t)rv, (uint64_t)rv,
|
||||
t->val, get_current_locale_str());
|
||||
}
|
||||
}
|
||||
if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
|
||||
printf("PASSED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", ->0x%" PRIX64 ")"
|
||||
" == %" PRIuPTR "\n", n_prnt(t->str.str), (intptr_t)t->num_of_digt,
|
||||
(intptr_t)t->str.len + 1, (uint64_t)rv, rs);
|
||||
}
|
||||
}
|
||||
return t_failed;
|
||||
}
|
||||
|
||||
|
||||
int check_strx_to_sizet_n_all_chars(void)
|
||||
{
|
||||
static const size_t n_checks = 256; /* from 0 to 255 */
|
||||
int c_failed[n_checks];
|
||||
size_t t_failed = 0;
|
||||
size_t j;
|
||||
|
||||
memset(c_failed, 0, sizeof(c_failed));
|
||||
|
||||
for(j = 0; j < locale_name_count; j++)
|
||||
{
|
||||
unsigned int c;
|
||||
size_t test_val;
|
||||
|
||||
set_test_locale(j); /* setlocale() can be slow! */
|
||||
for(c = 0; c < n_checks; c++)
|
||||
{
|
||||
static const size_t rnd_val = 98372558;
|
||||
size_t rs;
|
||||
size_t len;
|
||||
|
||||
if ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'))
|
||||
continue; /* skip xdigits */
|
||||
|
||||
for (len = 0; len <= 5; len++)
|
||||
{
|
||||
for(test_val = 0; test_val <= rnd_val&& !c_failed[c]; test_val += rnd_val)
|
||||
{
|
||||
char test_str[] = "0123";
|
||||
size_t rv = test_val;
|
||||
|
||||
test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
|
||||
rs = MHD_strx_to_sizet_n_(test_str, len, &rv);
|
||||
if (rs != 0)
|
||||
{
|
||||
t_failed++;
|
||||
c_failed[c] = !0;
|
||||
fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
|
||||
" returned %" PRIuPTR ", while expecting zero. Locale: %s\n",
|
||||
n_prnt(test_str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
|
||||
}
|
||||
else if (rv != test_val)
|
||||
{
|
||||
t_failed++;
|
||||
c_failed[c] = !0;
|
||||
fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", &ret_val)"
|
||||
" modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")."
|
||||
" Locale: %s\n",
|
||||
n_prnt(test_str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv, get_current_locale_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (verbose > 1 && j == locale_name_count - 1 && !c_failed[c])
|
||||
{
|
||||
char test_str[] = "0123";
|
||||
test_str[0] = (char) (unsigned char)c; /* replace first char with non-digit char */
|
||||
|
||||
printf("PASSED: MHD_strx_to_sizet_n_(\"%s\", 0..5, &ret_val) == 0, value of ret_val is unmodified\n",
|
||||
n_prnt(test_str));
|
||||
}
|
||||
}
|
||||
}
|
||||
return t_failed;
|
||||
}
|
||||
|
||||
|
||||
int check_strx_to_sizet_n_overflow(void)
|
||||
{
|
||||
size_t t_failed = 0;
|
||||
size_t i, j;
|
||||
static const size_t n_checks1 = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]);
|
||||
#if SIZE_MAX != UINT64_MAX
|
||||
static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]) +
|
||||
sizeof(xdstrs_w_values) / sizeof(xdstrs_w_values[0]);
|
||||
#else /* SIZE_MAX == UINT64_MAX */
|
||||
static const size_t n_checks = sizeof(strx_ovflw) / sizeof(strx_ovflw[0]);
|
||||
#endif /* SIZE_MAX == UINT64_MAX */
|
||||
int c_failed[n_checks];
|
||||
|
||||
memset(c_failed, 0, sizeof(c_failed));
|
||||
|
||||
for(j = 0; j < locale_name_count; j++)
|
||||
{
|
||||
set_test_locale(j); /* setlocale() can be slow! */
|
||||
for(i = 0; i < n_checks; i++)
|
||||
{
|
||||
size_t rs;
|
||||
static const size_t rnd_val = 4;
|
||||
size_t len;
|
||||
const char * str;
|
||||
size_t min_len, max_len;
|
||||
if (i < n_checks1)
|
||||
{
|
||||
const struct str_with_len * const t = strx_ovflw + i;
|
||||
str = t->str;
|
||||
min_len = t->len;
|
||||
max_len = t->len + 1;
|
||||
}
|
||||
#if SIZE_MAX != UINT64_MAX
|
||||
else
|
||||
{
|
||||
const struct str_with_value * const t = xdstrs_w_values + (i - n_checks1);
|
||||
if (t->val <= SIZE_MAX)
|
||||
continue; /* check only strings that should overflow size_t */
|
||||
|
||||
if (t->str.len < t->num_of_digt)
|
||||
{
|
||||
fprintf(stderr, "ERROR: xdstrs_w_values[%u] has wrong num_of_digt (%u): num_of_digt is expected"
|
||||
" to be less or equal to str.len (%u).\n",
|
||||
(unsigned int) (i - n_checks1), (unsigned int) t->num_of_digt,
|
||||
(unsigned int) t->str.len);
|
||||
return -1;
|
||||
}
|
||||
str = t->str.str;
|
||||
min_len = t->num_of_digt;
|
||||
max_len = t->str.len + 1;
|
||||
}
|
||||
#else /* SIZE_MAX == UINT64_MAX */
|
||||
else
|
||||
continue; /* silent compiler warning */
|
||||
#endif /* SIZE_MAX == UINT64_MAX */
|
||||
|
||||
for (len = min_len; len <= max_len; len++)
|
||||
{
|
||||
size_t test_val;
|
||||
for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
|
||||
{
|
||||
size_t rv = test_val;
|
||||
|
||||
rs = MHD_strx_to_sizet_n_(str, len, &rv);
|
||||
if (rs != 0)
|
||||
{
|
||||
t_failed++;
|
||||
c_failed[i] = !0;
|
||||
fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
|
||||
" returned %" PRIuPTR ", while expecting zero. Locale: %s\n",
|
||||
n_prnt(str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
|
||||
}
|
||||
else if (rv != test_val)
|
||||
{
|
||||
t_failed++;
|
||||
c_failed[i] = !0;
|
||||
fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", &ret_val)"
|
||||
" modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")."
|
||||
" Locale: %s\n", n_prnt(str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv,
|
||||
get_current_locale_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
|
||||
printf("PASSED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR "..%" PRIuPTR ", &ret_val) == 0,"
|
||||
" value of ret_val is unmodified\n", n_prnt(str), (uintptr_t)min_len,
|
||||
(uintptr_t)max_len);
|
||||
}
|
||||
}
|
||||
return t_failed;
|
||||
}
|
||||
|
||||
|
||||
int check_strx_to_sizet_n_no_val(void)
|
||||
{
|
||||
size_t t_failed = 0;
|
||||
size_t i, j;
|
||||
static const size_t n_checks = sizeof(str_no_num) / sizeof(str_no_num[0]);
|
||||
int c_failed[n_checks];
|
||||
|
||||
memset(c_failed, 0, sizeof(c_failed));
|
||||
|
||||
for(j = 0; j < locale_name_count; j++)
|
||||
{
|
||||
set_test_locale(j); /* setlocale() can be slow! */
|
||||
for(i = 0; i < n_checks; i++)
|
||||
{
|
||||
size_t rs;
|
||||
const struct str_with_len * const t = str_no_num + i;
|
||||
static const size_t rnd_val = 3214314212;
|
||||
size_t len;
|
||||
|
||||
for (len = 0; len <= t->len + 1; len++)
|
||||
{
|
||||
size_t test_val;
|
||||
for(test_val = 0; test_val <= rnd_val && !c_failed[i]; test_val += rnd_val)
|
||||
{
|
||||
size_t rv = test_val;
|
||||
|
||||
rs = MHD_strx_to_sizet_n_(t->str, len, &rv);
|
||||
if (rs != 0)
|
||||
{
|
||||
t_failed++;
|
||||
c_failed[i] = !0;
|
||||
fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", ->0x%" PRIX64 ")"
|
||||
" returned %" PRIuPTR ", while expecting zero. Locale: %s\n",
|
||||
n_prnt(t->str), (uintptr_t)len, (uint64_t)rv, (uintptr_t)rs, get_current_locale_str());
|
||||
}
|
||||
else if (rv != test_val)
|
||||
{
|
||||
t_failed++;
|
||||
c_failed[i] = !0;
|
||||
fprintf(stderr, "FAILED: MHD_strx_to_sizet_n_(\"%s\", %" PRIuPTR ", &ret_val)"
|
||||
" modified value of ret_val (before call: 0x%" PRIX64 ", after call 0x%" PRIX64 ")."
|
||||
" Locale: %s\n", n_prnt(t->str), (uintptr_t)len, (uint64_t)test_val, (uint64_t)rv,
|
||||
get_current_locale_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (verbose > 1 && j == locale_name_count - 1 && !c_failed[i])
|
||||
printf("PASSED: MHD_strx_to_sizet_n_(\"%s\", 0..%" PRIuPTR ", &ret_val) == 0,"
|
||||
" value of ret_val is unmodified\n", n_prnt(t->str),
|
||||
(uintptr_t)t->len + 1);
|
||||
}
|
||||
}
|
||||
return t_failed;
|
||||
}
|
||||
|
||||
|
||||
int check_strx_to_uint32_valid(void)
|
||||
{
|
||||
size_t t_failed = 0;
|
||||
@@ -2958,8 +2441,6 @@ int run_str_to_X_tests(void)
|
||||
{
|
||||
int str_to_uint64_fails = 0;
|
||||
int str_to_uint64_n_fails = 0;
|
||||
int strx_to_sizet_fails = 0;
|
||||
int strx_to_sizet_n_fails = 0;
|
||||
int strx_to_uint32_fails = 0;
|
||||
int strx_to_uint32_n_fails = 0;
|
||||
int strx_to_uint64_fails = 0;
|
||||
@@ -3090,130 +2571,6 @@ int run_str_to_X_tests(void)
|
||||
else if (verbose > 0)
|
||||
printf("PASSED: function MHD_str_to_uint64_n_() successfully passed all checks.\n\n");
|
||||
|
||||
res = check_strx_to_sizet_valid();
|
||||
if (res != 0)
|
||||
{
|
||||
if (res < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_valid().\n");
|
||||
return 99;
|
||||
}
|
||||
strx_to_sizet_fails += res;
|
||||
fprintf(stderr, "FAILED: testcase check_strx_to_sizet_valid() failed.\n\n");
|
||||
}
|
||||
else if (verbose > 1)
|
||||
printf("PASSED: testcase check_strx_to_sizet_valid() successfully passed.\n\n");
|
||||
|
||||
res = check_strx_to_sizet_all_chars();
|
||||
if (res != 0)
|
||||
{
|
||||
if (res < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_all_chars().\n");
|
||||
return 99;
|
||||
}
|
||||
strx_to_sizet_fails += res;
|
||||
fprintf(stderr, "FAILED: testcase check_strx_to_sizet_all_chars() failed.\n\n");
|
||||
}
|
||||
else if (verbose > 1)
|
||||
printf("PASSED: testcase check_strx_to_sizet_all_chars() successfully passed.\n\n");
|
||||
|
||||
res = check_strx_to_sizet_overflow();
|
||||
if (res != 0)
|
||||
{
|
||||
if (res < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_overflow().\n");
|
||||
return 99;
|
||||
}
|
||||
strx_to_sizet_fails += res;
|
||||
fprintf(stderr, "FAILED: testcase check_strx_to_sizet_overflow() failed.\n\n");
|
||||
}
|
||||
else if (verbose > 1)
|
||||
printf("PASSED: testcase check_strx_to_sizet_overflow() successfully passed.\n\n");
|
||||
|
||||
res = check_strx_to_sizet_no_val();
|
||||
if (res != 0)
|
||||
{
|
||||
if (res < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_no_val().\n");
|
||||
return 99;
|
||||
}
|
||||
strx_to_sizet_fails += res;
|
||||
fprintf(stderr, "FAILED: testcase check_strx_to_sizet_no_val() failed.\n\n");
|
||||
}
|
||||
else if (verbose > 1)
|
||||
printf("PASSED: testcase check_strx_to_sizet_no_val() successfully passed.\n\n");
|
||||
|
||||
if (strx_to_sizet_fails)
|
||||
fprintf(stderr, "FAILED: function MHD_strx_to_sizet_() failed %d time%s.\n\n",
|
||||
strx_to_sizet_fails, strx_to_sizet_fails == 1 ? "" : "s");
|
||||
else if (verbose > 0)
|
||||
printf("PASSED: function MHD_strx_to_sizet_() successfully passed all checks.\n\n");
|
||||
|
||||
res = check_strx_to_sizet_n_valid();
|
||||
if (res != 0)
|
||||
{
|
||||
if (res < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_n_valid().\n");
|
||||
return 99;
|
||||
}
|
||||
strx_to_sizet_n_fails += res;
|
||||
fprintf(stderr, "FAILED: testcase check_strx_to_sizet_n_valid() failed.\n\n");
|
||||
}
|
||||
else if (verbose > 1)
|
||||
printf("PASSED: testcase check_strx_to_sizet_n_valid() successfully passed.\n\n");
|
||||
|
||||
res = check_strx_to_sizet_n_all_chars();
|
||||
if (res != 0)
|
||||
{
|
||||
if (res < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_n_all_chars().\n");
|
||||
return 99;
|
||||
}
|
||||
strx_to_sizet_n_fails += res;
|
||||
fprintf(stderr, "FAILED: testcase check_strx_to_sizet_n_all_chars() failed.\n\n");
|
||||
}
|
||||
else if (verbose > 1)
|
||||
printf("PASSED: testcase check_strx_to_sizet_n_all_chars() successfully passed.\n\n");
|
||||
|
||||
res = check_strx_to_sizet_n_overflow();
|
||||
if (res != 0)
|
||||
{
|
||||
if (res < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_n_overflow().\n");
|
||||
return 99;
|
||||
}
|
||||
strx_to_sizet_n_fails += res;
|
||||
fprintf(stderr, "FAILED: testcase check_strx_to_sizet_n_overflow() failed.\n\n");
|
||||
}
|
||||
else if (verbose > 1)
|
||||
printf("PASSED: testcase check_strx_to_sizet_n_overflow() successfully passed.\n\n");
|
||||
|
||||
res = check_strx_to_sizet_n_no_val();
|
||||
if (res != 0)
|
||||
{
|
||||
if (res < 0)
|
||||
{
|
||||
fprintf(stderr, "ERROR: test internal error in check_strx_to_sizet_n_no_val().\n");
|
||||
return 99;
|
||||
}
|
||||
strx_to_sizet_n_fails += res;
|
||||
fprintf(stderr, "FAILED: testcase check_strx_to_sizet_n_no_val() failed.\n\n");
|
||||
}
|
||||
else if (verbose > 1)
|
||||
printf("PASSED: testcase check_strx_to_sizet_n_no_val() successfully passed.\n\n");
|
||||
|
||||
if (strx_to_sizet_n_fails)
|
||||
fprintf(stderr, "FAILED: function MHD_strx_to_sizet_n_() failed %d time%s.\n\n",
|
||||
strx_to_sizet_n_fails, strx_to_sizet_n_fails == 1 ? "" : "s");
|
||||
else if (verbose > 0)
|
||||
printf("PASSED: function MHD_strx_to_sizet_n_() successfully passed all checks.\n\n");
|
||||
|
||||
res = check_strx_to_uint32_valid();
|
||||
if (res != 0)
|
||||
{
|
||||
@@ -3463,7 +2820,6 @@ int run_str_to_X_tests(void)
|
||||
printf("PASSED: function MHD_strx_to_uint64_n_() successfully passed all checks.\n\n");
|
||||
|
||||
if (str_to_uint64_fails || str_to_uint64_n_fails ||
|
||||
strx_to_sizet_fails || strx_to_sizet_n_fails ||
|
||||
strx_to_uint32_fails || strx_to_uint32_n_fails ||
|
||||
strx_to_uint64_fails || strx_to_uint64_n_fails)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user