Support larger integer test arguments: C part
Change the type of signed integer arguments from int32_t to intmax_t.
This allows the C code to work with test function arguments with a range
larger than int32_t. A subsequent commit will change the .datax generator
to support larger types.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
diff --git a/tests/suites/host_test.function b/tests/suites/host_test.function
index 59b18d2..06f391f 100644
--- a/tests/suites/host_test.function
+++ b/tests/suites/host_test.function
@@ -32,21 +32,19 @@
*
* \return 0 if success else 1
*/
-int verify_int(char *str, int32_t *p_value)
+int verify_int(char *str, intmax_t *p_value)
{
char *end = NULL;
errno = 0;
+ /* Limit the range to long: for large integers, the test framework will
+ * use expressions anyway. */
long value = strtol(str, &end, 0);
if (errno == EINVAL || *end != '\0') {
mbedtls_fprintf(stderr,
"Expected integer for parameter and got: %s\n", str);
return KEY_VALUE_MAPPING_NOT_FOUND;
}
- if (errno == ERANGE
-#if LONG_MAX > 0x7fffffff
- || value > 0x7fffffffL || value < -0x80000000L
-#endif
- ) {
+ if (errno == ERANGE) {
mbedtls_fprintf(stderr, "Integer out of range: %s\n", str);
return KEY_VALUE_MAPPING_NOT_FOUND;
}
@@ -222,7 +220,7 @@
break;
}
} else if (strcmp(type, "int") == 0) {
- if (verify_int(val, &int_params_store->s32) == 0) {
+ if (verify_int(val, &int_params_store->sint) == 0) {
*out++ = (char *) int_params_store++;
} else {
ret = (DISPATCH_INVALID_TEST_DATA);
@@ -245,7 +243,7 @@
}
} else if (strcmp(type, "exp") == 0) {
int exp_id = strtol(val, NULL, 10);
- if (get_expression(exp_id, &int_params_store->s32) == 0) {
+ if (get_expression(exp_id, &int_params_store->sint) == 0) {
*out++ = (char *) int_params_store++;
} else {
ret = (DISPATCH_INVALID_TEST_DATA);