summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@chromium.org>2021-06-17 13:20:25 -0600
committerCommit Bot <commit-bot@chromium.org>2021-06-18 19:05:01 +0000
commit257acda4b812d01687710ac2565e60e8df203eb2 (patch)
treeb4d8daca0a7d8a8f85b4d0390ea5793cfcb60c42
parentf1e0e13b2b71bf8f97b6da4e3eab27fd17000292 (diff)
downloadchrome-ec-257acda4b812d01687710ac2565e60e8df203eb2.tar.gz
zephyr: update snprintf signature to be compatible with zephyr 2.6
Also update the tests for printf since the documentation makes no guarantee about negative size values. BRANCH=none BUG=b:190731415 TEST=build brya TEST=make run-printf Signed-off-by: Yuval Peress <peress@chromium.org> Change-Id: I5e773362f1f30a1beb95284e589e49db3a1d8800 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2970989 Commit-Queue: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Denis Brockus <dbrockus@chromium.org>
-rw-r--r--common/printf.c4
-rw-r--r--include/printf.h5
-rw-r--r--test/printf.c10
3 files changed, 8 insertions, 11 deletions
diff --git a/common/printf.c b/common/printf.c
index 039a83a92f..14226800b6 100644
--- a/common/printf.c
+++ b/common/printf.c
@@ -494,7 +494,7 @@ static int snprintf_addchar(void *context, int c)
return 0;
}
-int snprintf(char *str, int size, const char *format, ...)
+int snprintf(char *str, size_t size, const char *format, ...)
{
va_list args;
int rv;
@@ -506,7 +506,7 @@ int snprintf(char *str, int size, const char *format, ...)
return rv;
}
-int vsnprintf(char *str, int size, const char *format, va_list args)
+int vsnprintf(char *str, size_t size, const char *format, va_list args)
{
struct snprintf_context ctx;
int rv;
diff --git a/include/printf.h b/include/printf.h
index 91c17b428b..5c6373cf1e 100644
--- a/include/printf.h
+++ b/include/printf.h
@@ -9,6 +9,7 @@
#define __CROS_EC_PRINTF_H
#include <stdarg.h> /* For va_list */
+#include <stddef.h> /* For size_t */
#include "common.h"
/*
@@ -87,7 +88,7 @@ __stdlib_compat int vfnprintf(int (*addchar)(void *context, int c),
* @return EC_SUCCESS, or EC_ERROR_OVERFLOW if the output was truncated.
*/
__attribute__((__format__(__printf__, 3, 4)))
-__stdlib_compat int snprintf(char *str, int size, const char *format, ...);
+__stdlib_compat int snprintf(char *str, size_t size, const char *format, ...);
/**
* Print formatted output to a string.
@@ -101,7 +102,7 @@ __stdlib_compat int snprintf(char *str, int size, const char *format, ...);
* @return The string length written to str, or a negative value on error.
* The negative values can be -EC_ERROR_INVAL or -EC_ERROR_OVERFLOW.
*/
-__stdlib_compat int vsnprintf(char *str, int size, const char *format,
+__stdlib_compat int vsnprintf(char *str, size_t size, const char *format,
va_list args);
#endif /* !HIDE_EC_STDLIB */
diff --git a/test/printf.c b/test/printf.c
index ae85837cd5..f7e9b9dd2d 100644
--- a/test/printf.c
+++ b/test/printf.c
@@ -97,10 +97,6 @@ test_static int test_vsnprintf_args(void)
T(expect(/* expect an invalid args error */
EC_ERROR_INVAL, NO_BYTES_TOUCHED,
- /* given -1 as output size limit */
- false, -1, ""));
- T(expect(/* expect an invalid args error */
- EC_ERROR_INVAL, NO_BYTES_TOUCHED,
/* given 0 as output size limit */
false, 0, ""));
T(expect(/* expect SUCCESS */
@@ -209,13 +205,13 @@ test_static int test_vsnprintf_pointers(void)
T(expect_success(err_str, "%P", ptr));
/* %p by itself is invalid */
T(expect(EC_ERROR_INVAL, NO_BYTES_TOUCHED,
- false, -1, "%p"));
+ false, 0, "%p"));
/* %p with an unknown suffix is invalid */
T(expect(EC_ERROR_INVAL, NO_BYTES_TOUCHED,
- false, -1, "%p "));
+ false, 0, "%p "));
/* %p with an unknown suffix is invalid */
T(expect(EC_ERROR_INVAL, NO_BYTES_TOUCHED,
- false, -1, "%pQ"));
+ false, 0, "%pQ"));
/* Test %pb, binary format */
T(expect_success("0", "%pb", BINARY_VALUE(val, 0)));