static int
doapr_outch(char **sbuffer,
            char **buffer, size_t *currlen, size_t *maxlen, int c)
{
    OPENSSL_assert(*sbuffer != NULL || buffer != NULL);
    OPENSSL_assert(*currlen <= *maxlen);
    if (buffer && *currlen == *maxlen) {
        if (*maxlen > INT_MAX - BUFFER_INC)
            return 0;
        *maxlen += BUFFER_INC;
        if (*buffer == NULL) {
            *buffer = OPENSSL_malloc(*maxlen);
            if (*buffer == NULL)
                return 0;
            if (*currlen > 0) {
                OPENSSL_assert(*sbuffer != NULL);
                memcpy(*buffer, *sbuffer, *currlen);
            }
            *sbuffer = NULL;
        } else {
            char *tmpbuf;
            tmpbuf = OPENSSL_realloc(*buffer, *maxlen);
            if (tmpbuf == NULL)
                return 0;
            *buffer = tmpbuf;
        }
    }
    if (*currlen < *maxlen) {
        if (*sbuffer)
            (*sbuffer)[(*currlen)++] = (char)c;
        else
            (*buffer)[(*currlen)++] = (char)c;
    }
    return 1;
}
['int BIO_dump_indent_cb(int (*cb) (const void *data, size_t len, void *u),\n                       void *u, const char *s, int len, int indent)\n{\n    int ret = 0;\n    char buf[288 + 1];\n    int i, j, rows, trc, n;\n    unsigned char ch;\n    int dump_width;\n    trc = 0;\n#ifdef TRUNCATE\n    for (; (len > 0) && ((s[len - 1] == \' \') || (s[len - 1] == \'\\0\')); len--)\n        trc++;\n#endif\n    if (indent < 0)\n        indent = 0;\n    else if (indent > 128)\n        indent = 128;\n    dump_width = DUMP_WIDTH_LESS_INDENT(indent);\n    rows = len / dump_width;\n    if ((rows * dump_width) < len)\n        rows++;\n    for (i = 0; i < rows; i++) {\n        n = BIO_snprintf(buf, sizeof(buf), "%*s%04x - ", indent, "",\n                         i * dump_width);\n        for (j = 0; j < dump_width; j++) {\n            if (SPACE(buf, n, 3)) {\n                if (((i * dump_width) + j) >= len) {\n                    strcpy(buf + n, "   ");\n                } else {\n                    ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff;\n                    BIO_snprintf(buf + n, 4, "%02x%c", ch,\n                                 j == 7 ? \'-\' : \' \');\n                }\n                n += 3;\n            }\n        }\n        if (SPACE(buf, n, 2)) {\n            strcpy(buf + n, "  ");\n            n += 2;\n        }\n        for (j = 0; j < dump_width; j++) {\n            if (((i * dump_width) + j) >= len)\n                break;\n            if (SPACE(buf, n, 1)) {\n                ch = ((unsigned char)*(s + i * dump_width + j)) & 0xff;\n#ifndef CHARSET_EBCDIC\n                buf[n++] = ((ch >= \' \') && (ch <= \'~\')) ? ch : \'.\';\n#else\n                buf[n++] = ((ch >= os_toascii[\' \']) && (ch <= os_toascii[\'~\']))\n                           ? os_toebcdic[ch]\n                           : \'.\';\n#endif\n                buf[n] = \'\\0\';\n            }\n        }\n        if (SPACE(buf, n, 1)) {\n            buf[n++] = \'\\n\';\n            buf[n] = \'\\0\';\n        }\n        ret += cb((void *)buf, n, u);\n    }\n#ifdef TRUNCATE\n    if (trc > 0) {\n        n = BIO_snprintf(buf, sizeof(buf), "%*s%04x - <SPACES/NULS>\\n",\n                         indent, "", len + trc);\n        ret += cb((void *)buf, n, u);\n    }\n#endif\n    return ret;\n}', 'int BIO_snprintf(char *buf, size_t n, const char *format, ...)\n{\n    va_list args;\n    int ret;\n    va_start(args, format);\n    ret = BIO_vsnprintf(buf, n, format, args);\n    va_end(args);\n    return (ret);\n}', 'int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)\n{\n    size_t retlen;\n    int truncated;\n    if(!_dopr(&buf, NULL, &n, &retlen, &truncated, format, args))\n        return -1;\n    if (truncated)\n        return -1;\n    else\n        return (retlen <= INT_MAX) ? (int)retlen : -1;\n}', "static int\n_dopr(char **sbuffer,\n      char **buffer,\n      size_t *maxlen,\n      size_t *retlen, int *truncated, const char *format, va_list args)\n{\n    char ch;\n    int64_t value;\n    LDOUBLE fvalue;\n    char *strvalue;\n    int min;\n    int max;\n    int state;\n    int flags;\n    int cflags;\n    size_t currlen;\n    state = DP_S_DEFAULT;\n    flags = currlen = cflags = min = 0;\n    max = -1;\n    ch = *format++;\n    while (state != DP_S_DONE) {\n        if (ch == '\\0' || (buffer == NULL && currlen >= *maxlen))\n            state = DP_S_DONE;\n        switch (state) {\n        case DP_S_DEFAULT:\n            if (ch == '%')\n                state = DP_S_FLAGS;\n            else\n                if(!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch))\n                    return 0;\n            ch = *format++;\n            break;\n        case DP_S_FLAGS:\n            switch (ch) {\n            case '-':\n                flags |= DP_F_MINUS;\n                ch = *format++;\n                break;\n            case '+':\n                flags |= DP_F_PLUS;\n                ch = *format++;\n                break;\n            case ' ':\n                flags |= DP_F_SPACE;\n                ch = *format++;\n                break;\n            case '#':\n                flags |= DP_F_NUM;\n                ch = *format++;\n                break;\n            case '0':\n                flags |= DP_F_ZERO;\n                ch = *format++;\n                break;\n            default:\n                state = DP_S_MIN;\n                break;\n            }\n            break;\n        case DP_S_MIN:\n            if (isdigit((unsigned char)ch)) {\n                min = 10 * min + char_to_int(ch);\n                ch = *format++;\n            } else if (ch == '*') {\n                min = va_arg(args, int);\n                ch = *format++;\n                state = DP_S_DOT;\n            } else\n                state = DP_S_DOT;\n            break;\n        case DP_S_DOT:\n            if (ch == '.') {\n                state = DP_S_MAX;\n                ch = *format++;\n            } else\n                state = DP_S_MOD;\n            break;\n        case DP_S_MAX:\n            if (isdigit((unsigned char)ch)) {\n                if (max < 0)\n                    max = 0;\n                max = 10 * max + char_to_int(ch);\n                ch = *format++;\n            } else if (ch == '*') {\n                max = va_arg(args, int);\n                ch = *format++;\n                state = DP_S_MOD;\n            } else\n                state = DP_S_MOD;\n            break;\n        case DP_S_MOD:\n            switch (ch) {\n            case 'h':\n                cflags = DP_C_SHORT;\n                ch = *format++;\n                break;\n            case 'l':\n                if (*format == 'l') {\n                    cflags = DP_C_LLONG;\n                    format++;\n                } else\n                    cflags = DP_C_LONG;\n                ch = *format++;\n                break;\n            case 'q':\n            case 'j':\n                cflags = DP_C_LLONG;\n                ch = *format++;\n                break;\n            case 'L':\n                cflags = DP_C_LDOUBLE;\n                ch = *format++;\n                break;\n            case 'z':\n                cflags = DP_C_SIZE;\n                ch = *format++;\n                break;\n            default:\n                break;\n            }\n            state = DP_S_CONV;\n            break;\n        case DP_S_CONV:\n            switch (ch) {\n            case 'd':\n            case 'i':\n                switch (cflags) {\n                case DP_C_SHORT:\n                    value = (short int)va_arg(args, int);\n                    break;\n                case DP_C_LONG:\n                    value = va_arg(args, long int);\n                    break;\n                case DP_C_LLONG:\n                    value = va_arg(args, int64_t);\n                    break;\n                case DP_C_SIZE:\n                    value = va_arg(args, ossl_ssize_t);\n                    break;\n                default:\n                    value = va_arg(args, int);\n                    break;\n                }\n                if (!fmtint(sbuffer, buffer, &currlen, maxlen, value, 10, min,\n                            max, flags))\n                    return 0;\n                break;\n            case 'X':\n                flags |= DP_F_UP;\n            case 'x':\n            case 'o':\n            case 'u':\n                flags |= DP_F_UNSIGNED;\n                switch (cflags) {\n                case DP_C_SHORT:\n                    value = (unsigned short int)va_arg(args, unsigned int);\n                    break;\n                case DP_C_LONG:\n                    value = va_arg(args, unsigned long int);\n                    break;\n                case DP_C_LLONG:\n                    value = va_arg(args, uint64_t);\n                    break;\n                case DP_C_SIZE:\n                    value = va_arg(args, size_t);\n                    break;\n                default:\n                    value = va_arg(args, unsigned int);\n                    break;\n                }\n                if (!fmtint(sbuffer, buffer, &currlen, maxlen, value,\n                            ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),\n                            min, max, flags))\n                    return 0;\n                break;\n            case 'f':\n                if (cflags == DP_C_LDOUBLE)\n                    fvalue = va_arg(args, LDOUBLE);\n                else\n                    fvalue = va_arg(args, double);\n                if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,\n                           flags, F_FORMAT))\n                    return 0;\n                break;\n            case 'E':\n                flags |= DP_F_UP;\n            case 'e':\n                if (cflags == DP_C_LDOUBLE)\n                    fvalue = va_arg(args, LDOUBLE);\n                else\n                    fvalue = va_arg(args, double);\n                if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,\n                           flags, E_FORMAT))\n                    return 0;\n                break;\n            case 'G':\n                flags |= DP_F_UP;\n            case 'g':\n                if (cflags == DP_C_LDOUBLE)\n                    fvalue = va_arg(args, LDOUBLE);\n                else\n                    fvalue = va_arg(args, double);\n                if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,\n                           flags, G_FORMAT))\n                    return 0;\n                break;\n            case 'c':\n                if(!doapr_outch(sbuffer, buffer, &currlen, maxlen,\n                            va_arg(args, int)))\n                    return 0;\n                break;\n            case 's':\n                strvalue = va_arg(args, char *);\n                if (max < 0) {\n                    if (buffer)\n                        max = INT_MAX;\n                    else\n                        max = *maxlen;\n                }\n                if (!fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,\n                            flags, min, max))\n                    return 0;\n                break;\n            case 'p':\n                value = (size_t)va_arg(args, void *);\n                if (!fmtint(sbuffer, buffer, &currlen, maxlen,\n                            value, 16, min, max, flags | DP_F_NUM))\n                    return 0;\n                break;\n            case 'n':\n                {\n                    int *num;\n                    num = va_arg(args, int *);\n                    *num = currlen;\n                }\n                break;\n            case '%':\n                if(!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch))\n                    return 0;\n                break;\n            case 'w':\n                ch = *format++;\n                break;\n            default:\n                break;\n            }\n            ch = *format++;\n            state = DP_S_DEFAULT;\n            flags = cflags = min = 0;\n            max = -1;\n            break;\n        case DP_S_DONE:\n            break;\n        default:\n            break;\n        }\n    }\n    if (buffer == NULL) {\n        *truncated = (currlen > *maxlen - 1);\n        if (*truncated)\n            currlen = *maxlen - 1;\n    }\n    if(!doapr_outch(sbuffer, buffer, &currlen, maxlen, '\\0'))\n        return 0;\n    *retlen = currlen - 1;\n    return 1;\n}", 'static int\ndoapr_outch(char **sbuffer,\n            char **buffer, size_t *currlen, size_t *maxlen, int c)\n{\n    OPENSSL_assert(*sbuffer != NULL || buffer != NULL);\n    OPENSSL_assert(*currlen <= *maxlen);\n    if (buffer && *currlen == *maxlen) {\n        if (*maxlen > INT_MAX - BUFFER_INC)\n            return 0;\n        *maxlen += BUFFER_INC;\n        if (*buffer == NULL) {\n            *buffer = OPENSSL_malloc(*maxlen);\n            if (*buffer == NULL)\n                return 0;\n            if (*currlen > 0) {\n                OPENSSL_assert(*sbuffer != NULL);\n                memcpy(*buffer, *sbuffer, *currlen);\n            }\n            *sbuffer = NULL;\n        } else {\n            char *tmpbuf;\n            tmpbuf = OPENSSL_realloc(*buffer, *maxlen);\n            if (tmpbuf == NULL)\n                return 0;\n            *buffer = tmpbuf;\n        }\n    }\n    if (*currlen < *maxlen) {\n        if (*sbuffer)\n            (*sbuffer)[(*currlen)++] = (char)c;\n        else\n            (*buffer)[(*currlen)++] = (char)c;\n    }\n    return 1;\n}']