From 21a3a28980b08002008918944d26e92d4ad7f791 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Tue, 29 Aug 2017 12:06:40 -0400 Subject: [PATCH] Copy args so we can re-use it. --- .travis.yml | 2 +- core/c/mpw-util.c | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 633fad91..456011f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,6 @@ git: submodules: true script: - "( brew install libsodium json-c )" - - "( cd ./platform-independent/cli-c && ./clean && targets='mpw mpw-bench mpw-tests' ./build && ./mpw-tests )" + - "( cd ./platform-independent/cli-c && ./clean && targets='mpw mpw-bench mpw-tests' ./build && ./mpw-tests && ./mpw-cli-tests )" - "( xcodebuild -workspace platform-darwin/MasterPassword.xcworkspace -configuration 'Test' -scheme 'MasterPassword iOS' -sdk iphonesimulator )" - "( xcodebuild -workspace platform-darwin/MasterPassword.xcworkspace -configuration 'Test' -scheme 'MasterPassword macOS' )" diff --git a/core/c/mpw-util.c b/core/c/mpw-util.c index 64378614..7d2fe932 100644 --- a/core/c/mpw-util.c +++ b/core/c/mpw-util.c @@ -360,11 +360,15 @@ const char *mpw_vstr(const char *format, va_list args) { // TODO: Not thread-safe static char *str_str; static size_t str_str_max; - if (!str_str && !(str_str = calloc( str_str_max = 1, 1 ))) + if (!str_str && !(str_str = calloc( str_str_max = 1, sizeof( char ) ))) return NULL; do { - size_t len = (size_t)vsnprintf( str_str, str_str_max, format, args ); + va_list args_attempt; + va_copy( args_attempt, args ); + size_t len = (size_t)vsnprintf( str_str, str_str_max, format, args_attempt ); + va_end( args_attempt ); + if ((int)len < 0) return NULL; if (len < str_str_max)