# HG changeset patch # User Matt Johnston # Date 1648786248 -28800 # Node ID 83b6a47759a8070d50db67e67464dde70792bb0d # Parent e093ddc5b585823c490c4d7416f46a446c97d55f Add m_snprintf() that won't return negative diff -r e093ddc5b585 -r 83b6a47759a8 dbutil.c --- a/dbutil.c Fri Apr 01 11:56:10 2022 +0800 +++ b/dbutil.c Fri Apr 01 12:10:48 2022 +0800 @@ -771,3 +771,16 @@ return FD_ISSET(fd, &fds); } } + +int m_snprintf(char *str, size_t size, const char *format, ...) { + va_list param; + int ret; + + va_start(param, format); + ret = vsnprintf(str, size, format, param); + va_end(param); + if (ret < 0) { + dropbear_exit("snprintf failed"); + } + return ret; +} diff -r e093ddc5b585 -r 83b6a47759a8 dbutil.h --- a/dbutil.h Fri Apr 01 11:56:10 2022 +0800 +++ b/dbutil.h Fri Apr 01 12:10:48 2022 +0800 @@ -73,6 +73,8 @@ void setnonblocking(int fd); void disallow_core(void); int m_str_to_uint(const char* str, unsigned int *val); +/* The same as snprintf() but exits rather than returning negative */ +int m_snprintf(char *str, size_t size, const char *format, ...); /* Used to force mp_ints to be initialised */ #define DEF_MP_INT(X) mp_int X = {0, 0, 0, NULL}