X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/3e607d23543f0f3fb7b72953b89334071540667f..79b34efe9229265da3e0b0995e8828e29c4d5dd9:/util.c diff --git a/util.c b/util.c index d9c87ece..5b16fc4b 100644 --- a/util.c +++ b/util.c @@ -633,26 +633,19 @@ int vslprintf(char *str, int n, const char *format, va_list ap) buf = malloc(len); if (!buf) { /* can't call debug or we would recurse */ - exit(1); + exit_cleanup(1); } } - ret = vsprintf(buf, format, ap); - - if (ret < 0) { - str[0] = 0; - return -1; - } - - if (ret < n) { - n = ret; - } else if (ret > n) { - ret = -1; + vsprintf(buf, format, ap); + ret = strlen(buf); + if (ret > n) { + /* yikes! */ + exit_cleanup(1); } - - buf[n] = 0; + buf[ret] = 0; - memcpy(str, buf, n+1); + memcpy(str, buf, ret+1); return ret; #endif @@ -670,3 +663,4 @@ int slprintf(char *str, int n, char *format, ...) va_end(ap); return ret; } +