static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
{
    int j, len;
    const char *s, *ss, *p;
    if (dir == NULL || !*dir) {
        X509err(X509_F_ADD_CERT_DIR, X509_R_INVALID_DIRECTORY);
        return 0;
    }
    s = dir;
    p = s;
    do {
        if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\0')) {
            BY_DIR_ENTRY *ent;
            ss = s;
            s = p + 1;
            len = (int)(p - ss);
            if (len == 0)
                continue;
            for (j = 0; j < sk_BY_DIR_ENTRY_num(ctx->dirs); j++) {
                ent = sk_BY_DIR_ENTRY_value(ctx->dirs, j);
                if (strlen(ent->dir) == (size_t)len &&
                    strncmp(ent->dir, ss, (unsigned int)len) == 0)
                    break;
            }
            if (j < sk_BY_DIR_ENTRY_num(ctx->dirs))
                continue;
            if (ctx->dirs == NULL) {
                ctx->dirs = sk_BY_DIR_ENTRY_new_null();
                if (!ctx->dirs) {
                    X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE);
                    return 0;
                }
            }
            ent = OPENSSL_malloc(sizeof(*ent));
            if (ent == NULL)
                return 0;
            ent->dir_type = type;
            ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp);
            ent->dir = OPENSSL_malloc((unsigned int)len + 1);
            if (ent->dir == NULL || ent->hashes == NULL) {
                by_dir_entry_free(ent);
                return 0;
            }
            strncpy(ent->dir, ss, (unsigned int)len);
            ent->dir[len] = '\0';
            if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) {
                by_dir_entry_free(ent);
                return 0;
            }
        }
    } while (*p++ != '\0');
    return 1;
}
["static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)\n{\n    int j, len;\n    const char *s, *ss, *p;\n    if (dir == NULL || !*dir) {\n        X509err(X509_F_ADD_CERT_DIR, X509_R_INVALID_DIRECTORY);\n        return 0;\n    }\n    s = dir;\n    p = s;\n    do {\n        if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\\0')) {\n            BY_DIR_ENTRY *ent;\n            ss = s;\n            s = p + 1;\n            len = (int)(p - ss);\n            if (len == 0)\n                continue;\n            for (j = 0; j < sk_BY_DIR_ENTRY_num(ctx->dirs); j++) {\n                ent = sk_BY_DIR_ENTRY_value(ctx->dirs, j);\n                if (strlen(ent->dir) == (size_t)len &&\n                    strncmp(ent->dir, ss, (unsigned int)len) == 0)\n                    break;\n            }\n            if (j < sk_BY_DIR_ENTRY_num(ctx->dirs))\n                continue;\n            if (ctx->dirs == NULL) {\n                ctx->dirs = sk_BY_DIR_ENTRY_new_null();\n                if (!ctx->dirs) {\n                    X509err(X509_F_ADD_CERT_DIR, ERR_R_MALLOC_FAILURE);\n                    return 0;\n                }\n            }\n            ent = OPENSSL_malloc(sizeof(*ent));\n            if (ent == NULL)\n                return 0;\n            ent->dir_type = type;\n            ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp);\n            ent->dir = OPENSSL_malloc((unsigned int)len + 1);\n            if (ent->dir == NULL || ent->hashes == NULL) {\n                by_dir_entry_free(ent);\n                return 0;\n            }\n            strncpy(ent->dir, ss, (unsigned int)len);\n            ent->dir[len] = '\\0';\n            if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) {\n                by_dir_entry_free(ent);\n                return 0;\n            }\n        }\n    } while (*p++ != '\\0');\n    return 1;\n}", 'int sk_num(const _STACK *st)\n{\n    if (st == NULL)\n        return -1;\n    return st->num;\n}', '_STACK *sk_new_null(void)\n{\n    return sk_new((int (*)(const void *, const void *))0);\n}', '_STACK *sk_new(int (*c) (const void *, const void *))\n{\n    _STACK *ret;\n    if ((ret = OPENSSL_zalloc(sizeof(_STACK))) == NULL)\n        goto err;\n    if ((ret->data = OPENSSL_zalloc(sizeof(*ret->data) * MIN_NODES)) == NULL)\n        goto err;\n    ret->comp = c;\n    ret->num_alloc = MIN_NODES;\n    return (ret);\n err:\n    OPENSSL_free(ret);\n    return (NULL);\n}', 'void *CRYPTO_zalloc(size_t num, const char *file, int line)\n{\n    void *ret = CRYPTO_malloc(num, file, line);\n    if (ret != NULL)\n        memset(ret, 0, num);\n    return ret;\n}', 'void *CRYPTO_malloc(size_t num, const char *file, int line)\n{\n    void *ret = NULL;\n    if (num <= 0)\n        return NULL;\n    allow_customize = 0;\n#ifndef OPENSSL_NO_CRYPTO_MDEBUG\n    if (call_malloc_debug) {\n        CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);\n        ret = malloc(num);\n        CRYPTO_mem_debug_malloc(ret, num, 1, file, line);\n    } else {\n        ret = malloc(num);\n    }\n#else\n    (void)file;\n    (void)line;\n    ret = malloc(num);\n#endif\n#ifndef OPENSSL_CPUID_OBJ\n    if (ret && (num > 2048)) {\n        extern unsigned char cleanse_ctr;\n        ((unsigned char *)ret)[0] = cleanse_ctr;\n    }\n#endif\n    return ret;\n}', 'int sk_push(_STACK *st, void *data)\n{\n    return (sk_insert(st, data, st->num));\n}', 'int sk_insert(_STACK *st, void *data, int loc)\n{\n    char **s;\n    if (st == NULL)\n        return 0;\n    if (st->num_alloc <= st->num + 1) {\n        s = OPENSSL_realloc((char *)st->data,\n                            (unsigned int)sizeof(char *) * st->num_alloc * 2);\n        if (s == NULL)\n            return (0);\n        st->data = s;\n        st->num_alloc *= 2;\n    }\n    if ((loc >= (int)st->num) || (loc < 0))\n        st->data[st->num] = data;\n    else {\n        memmove(&(st->data[loc + 1]),\n                &(st->data[loc]), sizeof(char *) * (st->num - loc));\n        st->data[loc] = data;\n    }\n    st->num++;\n    st->sorted = 0;\n    return (st->num);\n}', 'void *sk_value(const _STACK *st, int i)\n{\n    if (!st || (i < 0) || (i >= st->num))\n        return NULL;\n    return st->data[i];\n}']