aboutsummaryrefslogtreecommitdiff
path: root/helper
diff options
context:
space:
mode:
authorJere Leppänen <jere.leppanen@nokia.com>2022-09-02 10:17:01 +0300
committerMatias Elo <matias.elo@nokia.com>2022-09-08 13:49:17 +0300
commit2d4280b47a0445187e18752ce91e2d76fd05fd50 (patch)
tree355421f7499498d2c21b1e779b84951211bf1f67 /helper
parent268dda74af76b64ce9a5ac62e02f66ae0347ce59 (diff)
helper: cli: check for vsnprintf errors
If vsnprintf() fails, log an error and return error status. Signed-off-by: Jere Leppänen <jere.leppanen@nokia.com> Reviewed-by: Tuomas Taipale <tuomas.taipale@nokia.com>
Diffstat (limited to 'helper')
-rw-r--r--helper/cli.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/helper/cli.c b/helper/cli.c
index a514086e2..6a0230c50 100644
--- a/helper/cli.c
+++ b/helper/cli.c
@@ -206,7 +206,7 @@ static int cli_log_va(odp_log_level_t level, const char *fmt, va_list in_args)
(void)level;
va_list args;
- char *str, *p, *last;
+ char *str = NULL, *p, *last;
int len;
/*
@@ -221,8 +221,15 @@ static int cli_log_va(odp_log_level_t level, const char *fmt, va_list in_args)
* string after the last newline and use it the next time we're called.
*/
va_copy(args, in_args);
- len = vsnprintf(NULL, 0, fmt, args) + 1;
+ len = vsnprintf(NULL, 0, fmt, args);
va_end(args);
+
+ if (len < 0) {
+ ODPH_ERR("vsnprintf failed\n");
+ goto out;
+ }
+
+ len++;
str = malloc(len);
if (!str) {
@@ -231,8 +238,14 @@ static int cli_log_va(odp_log_level_t level, const char *fmt, va_list in_args)
}
va_copy(args, in_args);
- vsnprintf(str, len, fmt, args);
+ len = vsnprintf(str, len, fmt, args);
va_end(args);
+
+ if (len < 0) {
+ ODPH_ERR("vsnprintf failed\n");
+ goto out;
+ }
+
p = str;
last = strrchr(p, '\n');