BIO_printf() can fail to print the last character
[openssl.git] / crypto / bio / b_print.c
index 1b70bac71b1d6350dfe3d766026ac6e21a3b407c..6808cdc6de65cac84620dc96afafd477575c3c24 100644 (file)
@@ -363,9 +363,15 @@ _dopr(char **sbuffer,
             break;
         }
     }
-    *truncated = (currlen > *maxlen - 1);
-    if (*truncated)
-        currlen = *maxlen - 1;
+    /*
+     * We have to truncate if there is no dynamic buffer and we have filled the
+     * static buffer.
+     */
+    if (buffer == NULL) {
+        *truncated = (currlen > *maxlen - 1);
+        if (*truncated)
+            currlen = *maxlen - 1;
+    }
     if(!doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0'))
         return 0;
     *retlen = currlen - 1;