vlc->table_size += size;
if (vlc->table_size > vlc->table_allocated) {
+ int err;
if (use_static)
- abort(); // cannot do anything, init_vlc() is used with too little memory
+ return AVERROR_BUG;
vlc->table_allocated += (1 << vlc->bits);
- vlc->table = av_realloc(vlc->table, sizeof(VLC_TYPE) * 2 * vlc->table_allocated);
- if (!vlc->table)
- return -1;
+ if ((err = av_reallocp(&vlc->table,
+ sizeof(VLC_TYPE) * 2 *
+ vlc->table_allocated)) < 0) {
+ vlc->table_allocated = 0;
+ vlc->table_size = 0;
+ return err;
+ }
}
return index;
}
table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_NEW_STATIC);
av_dlog(NULL, "new table index=%d size=%d\n", table_index, table_size);
if (table_index < 0)
- return -1;
+ return table_index;
table = &vlc->table[table_index];
for (i = 0; i < table_size; i++) {
av_dlog(NULL, "%4x: code=%d n=%d\n", j, i, n);
if (table[j][1] /*bits*/ != 0) {
av_log(NULL, AV_LOG_ERROR, "incorrect codes\n");
- return -1;
+ return AVERROR_INVALIDDATA;
}
table[j][1] = n; //bits
table[j][0] = symbol;
j, codes[i].bits + table_nb_bits);
index = build_table(vlc, subtable_bits, k-i, codes+i, flags);
if (index < 0)
- return -1;
+ return index;
/* note: realloc has been done, so reload tables */
table = &vlc->table[table_index];
table[j][0] = index; //code
if (vlc->table_size && vlc->table_size == vlc->table_allocated) {
return 0;
} else if (vlc->table_size) {
- abort(); // fatal error, we are called on a partially initialized table
+ return AVERROR_BUG;
}
} else {
vlc->table = NULL;
av_dlog(NULL, "build table nb_codes=%d\n", nb_codes);
buf = av_malloc((nb_codes + 1) * sizeof(VLCcode));
+ if (!buf)
+ return AVERROR(ENOMEM);
assert(symbols_size <= 2 || !symbols);
j = 0;
av_free(buf);
if (ret < 0) {
av_freep(&vlc->table);
- return -1;
+ return ret;
}
if ((flags & INIT_VLC_USE_NEW_STATIC) &&
vlc->table_size != vlc->table_allocated)