diff --git a/openbsd-compat/bsd-snprintf.c b/openbsd-compat/bsd-snprintf.c index bc505b838..0d23a86c5 100644 --- a/openbsd-compat/bsd-snprintf.c +++ b/openbsd-compat/bsd-snprintf.c @@ -320,7 +320,7 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) value = va_arg (args, int); if (fmtint(buffer, &currlen, maxlen, value, 10, min, max, flags) == -1) - return -1; + goto fail; break; case 'o': flags |= DP_F_UNSIGNED; @@ -340,7 +340,7 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) value = (long)va_arg (args, unsigned int); if (fmtint(buffer, &currlen, maxlen, value, 8, min, max, flags) == -1) - return -1; + goto fail; break; case 'u': flags |= DP_F_UNSIGNED; @@ -360,7 +360,7 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) value = (long)va_arg (args, unsigned int); if (fmtint(buffer, &currlen, maxlen, value, 10, min, max, flags) == -1) - return -1; + goto fail; break; case 'X': flags |= DP_F_UP; @@ -382,7 +382,7 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) value = (long)va_arg (args, unsigned int); if (fmtint(buffer, &currlen, maxlen, value, 16, min, max, flags) == -1) - return -1; + goto fail; break; case 'f': if (cflags == DP_C_LDOUBLE) @@ -391,7 +391,7 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) fvalue = va_arg (args, double); if (fmtfp(buffer, &currlen, maxlen, fvalue, min, max, flags) == -1) - return -1; + goto fail; break; case 'E': flags |= DP_F_UP; @@ -402,7 +402,7 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) fvalue = va_arg (args, double); if (fmtfp(buffer, &currlen, maxlen, fvalue, min, max, flags) == -1) - return -1; + goto fail; break; case 'G': flags |= DP_F_UP; @@ -413,7 +413,7 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) fvalue = va_arg (args, double); if (fmtfp(buffer, &currlen, maxlen, fvalue, min, max, flags) == -1) - return -1; + goto fail; break; case 'c': DOPR_OUTCH(buffer, currlen, maxlen, @@ -428,13 +428,13 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) if (min > 0 && max >= 0 && min > max) max = min; if (fmtstr(buffer, &currlen, maxlen, strvalue, flags, min, max) == -1) - return -1; + goto fail; break; case 'p': strvalue = va_arg (args, void *); if (fmtint(buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags) == -1) - return -1; + goto fail; break; #if we_dont_want_this_in_openssh case 'n': @@ -494,8 +494,11 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) else if (maxlen > 0) buffer[maxlen - 1] = '\0'; } - + va_end(args); return currlen < INT_MAX ? (int)currlen : -1; + fail: + va_end(args); + return -1; } static int