diff --git a/lib/libc/minimal/source/stdout/sprintf.c b/lib/libc/minimal/source/stdout/sprintf.c index 98dcabf0eca..081312046d0 100644 --- a/lib/libc/minimal/source/stdout/sprintf.c +++ b/lib/libc/minimal/source/stdout/sprintf.c @@ -45,12 +45,8 @@ int snprintf(char *_Restrict s, size_t len, const char *_Restrict format, ...) int r; char dummy; - if ((int) len <= 0) { - if (len == 0) { - s = &dummy; /* write final NUL to dummy, since can't change *s */ - } else { - len = 0x7fffffff; /* allow up to "maxint" characters */ - } + if (len == 0) { + s = &dummy; /* write final NUL to dummy, can't change *s */ } p.ptr = s; @@ -88,12 +84,8 @@ int vsnprintf(char *_Restrict s, size_t len, const char *_Restrict format, va_li int r; char dummy; - if ((int) len <= 0) { - if (len == 0) { - s = &dummy; /* write final NUL to dummy, since can't change *s */ - } else { - len = 0x7fffffff; /* allow up to "maxint" characters */ - } + if (len == 0) { + s = &dummy; /* write final NUL to dummy, can't change * *s */ } p.ptr = s; diff --git a/tests/kernel/test_sprintf/src/test_sprintf.c b/tests/kernel/test_sprintf/src/test_sprintf.c index ea5b6962893..ed76b86f04b 100644 --- a/tests/kernel/test_sprintf/src/test_sprintf.c +++ b/tests/kernel/test_sprintf/src/test_sprintf.c @@ -235,27 +235,6 @@ int vsnprintfTest(void) int status = TC_PASS; char buffer[100]; - /* - * The string size may be handled in a non-standard manner. - * If a negative value is supplied for the string size, it is converted - * to 0x7fffffff--maximum integer size. Since there is insufficient - * memory to test a string of that length, we just check that the string - * was fully written so that we can exercise the code path. - */ - buffer[0] = '\0'; - len = tvsnprintf(buffer, (size_t)(-4), "%x", DEADBEEF); - if (len != strlen(DEADBEEF_LHEX_STR)) { - TC_ERROR("vsnprintf(%%x). Expected return value %d, not %d\n", - strlen(DEADBEEF_LHEX_STR), len); - status = TC_FAIL; - } - - if (strcmp(buffer, DEADBEEF_LHEX_STR) != 0) { - TC_ERROR("vsnprintf(%%x). Expected '%s', got '%s'\n", - DEADBEEF_LHEX_STR, buffer); - status = TC_FAIL; - } - /*******************/ buffer[0] = '\0'; len = tvsnprintf(buffer, 0, "%x", DEADBEEF); @@ -356,26 +335,6 @@ int snprintfTest(void) int status = TC_PASS; char buffer[100]; - /* - * The string size may be handled in a non-standard manner. - * If a negative value is supplied for the string size, it is converted - * to 0x7fffffff--maximum integer size. Since there is insufficient - * memory to test a string of that length, we just check that the string - * was fully written so that we can exercise the code path. - */ - buffer[0] = '\0'; - len = snprintf(buffer, (size_t)(-4), "%x", DEADBEEF); - if (len != strlen(DEADBEEF_LHEX_STR)) { - TC_ERROR("snprintf(%%x). Expected return value %d, not %d\n", - strlen(DEADBEEF_LHEX_STR), len); - status = TC_FAIL; - } - - if (strcmp(buffer, DEADBEEF_LHEX_STR) != 0) { - TC_ERROR("snprintf(%%x). Expected '%s', got '%s'\n", - DEADBEEF_LHEX_STR, buffer); - status = TC_FAIL; - } /*******************/ buffer[0] = '\0';