From: Alan T. DeKok Date: Fri, 18 Sep 2015 13:10:34 +0000 (-0400) Subject: outlen may be zero, too X-Git-Tag: release_3_0_10~66 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d32d2c0472d09756c0ac68c03be10573a0d5edd0;p=thirdparty%2Ffreeradius-server.git outlen may be zero, too --- diff --git a/src/lib/print.c b/src/lib/print.c index 62597e56815..0d11ef798c4 100644 --- a/src/lib/print.c +++ b/src/lib/print.c @@ -166,11 +166,11 @@ char const *fr_utf8_strchr(int *chr_len, char const *str, char const *chr) * @note Will always \0 terminate unless outlen == 0. * * @param[in] in string to escape. - * @param[in] inlen length of string to escape (lets us deal with embedded NULLs) + * @param[in] inlen length of string to escape (lets us deal with embedded NULs) * @param[out] out where to write the escaped string. * @param[out] outlen the length of the buffer pointed to by out. * @param[in] quote the quotation character - * @return the number of bytes written to the out buffer, or a number >= outlen if truncation has occurred. + * @return the number of bytes it WOULD HAVE written to the buffer, not including the trailing NUL */ size_t fr_prints(char *out, size_t outlen, char const *in, ssize_t inlen, char quote) { @@ -181,7 +181,7 @@ size_t fr_prints(char *out, size_t outlen, char const *in, ssize_t inlen, char q /* No input, so no output... */ if (!in) { - if (out) *out = '\0'; + if (out && outlen) *out = '\0'; return 0; } @@ -362,7 +362,7 @@ size_t fr_prints(char *out, size_t outlen, char const *in, ssize_t inlen, char q * @param in string to calculate the escaped length for. * @param inlen length of the input string, if < 0 strlen will be used to check the length. * @param[in] quote the quotation character. - * @return the size of buffer required to hold the escaped string including the NULL byte. + * @return the size of buffer required to hold the escaped string including the NUL byte. */ size_t fr_prints_len(char const *in, ssize_t inlen, char quote) {