static int mkv_add_seekhead_entry(mkv_seekhead *seekhead, unsigned int elementid, uint64_t filepos)
{
    int err;
    if (seekhead->max_entries > 0 && seekhead->max_entries <= seekhead->num_entries)
        return -1;
    if ((err = av_reallocp_array(&seekhead->entries, seekhead->num_entries + 1,
                                 sizeof(*seekhead->entries))) < 0) {
        seekhead->num_entries = 0;
        return err;
    }
    seekhead->entries[seekhead->num_entries].elementid    = elementid;
    seekhead->entries[seekhead->num_entries++].segmentpos = filepos - seekhead->segment_offset;
    return 0;
}
['static int mkv_add_seekhead_entry(mkv_seekhead *seekhead, unsigned int elementid, uint64_t filepos)\n{\n    int err;\n    if (seekhead->max_entries > 0 && seekhead->max_entries <= seekhead->num_entries)\n        return -1;\n    if ((err = av_reallocp_array(&seekhead->entries, seekhead->num_entries + 1,\n                                 sizeof(*seekhead->entries))) < 0) {\n        seekhead->num_entries = 0;\n        return err;\n    }\n    seekhead->entries[seekhead->num_entries].elementid    = elementid;\n    seekhead->entries[seekhead->num_entries++].segmentpos = filepos - seekhead->segment_offset;\n    return 0;\n}', 'int av_reallocp_array(void *ptr, size_t nmemb, size_t size)\n{\n    void **ptrptr = ptr;\n    void *ret;\n    if (!size || nmemb >= INT_MAX / size)\n        return AVERROR(ENOMEM);\n    if (!nmemb) {\n        av_freep(ptr);\n        return 0;\n    }\n    ret = av_realloc(*ptrptr, nmemb * size);\n    if (!ret) {\n        av_freep(ptr);\n        return AVERROR(ENOMEM);\n    }\n    *ptrptr = ret;\n    return 0;\n}', 'void av_freep(void *arg)\n{\n    void **ptr = (void **)arg;\n    av_free(*ptr);\n    *ptr = NULL;\n}', 'void av_free(void *ptr)\n{\n#if CONFIG_MEMALIGN_HACK\n    if (ptr)\n        free((char *)ptr - ((char *)ptr)[-1]);\n#elif HAVE_ALIGNED_MALLOC\n    _aligned_free(ptr);\n#else\n    free(ptr);\n#endif\n}']