if (options->num_matching_paths > options->array_size) {
options->array_size++;
options->array_size *= 2;
- options->data = para_realloc(options->data, options->array_size
- * sizeof(*options->data));
+ options->data = arr_realloc(options->data, options->array_size,
+ sizeof(*options->data));
}
d = options->data + tmp;
ret = get_afsi_of_row(aft_row, &d->afsi);
struct lls_parse_result *flpr;
filter_num = filter_setup(cmdline, &cfg, &flpr);
- a->filter_lpr = para_realloc(a->filter_lpr,
- (nf + 1) * sizeof(flpr));
- a->filter_conf = para_realloc(a->filter_conf,
- (nf + 1) * sizeof(void *));
- a->filter_nums = para_realloc(a->filter_nums,
- (nf + 1) * sizeof(unsigned));
+ a->filter_lpr = arr_realloc(a->filter_lpr, nf + 1, sizeof(flpr));
+ a->filter_conf = arr_realloc(a->filter_conf, nf + 1, sizeof(void *));
+ a->filter_nums = arr_realloc(a->filter_nums, nf + 1, sizeof(unsigned));
a->filter_nums[nf] = filter_num;
a->filter_conf[nf] = cfg;
vlc->table_size += size;
if (vlc->table_size > vlc->table_allocated) {
vlc->table_allocated += (1 << vlc->bits);
- vlc->table = para_realloc(vlc->table,
- sizeof(int16_t) * 2 * vlc->table_allocated);
+ vlc->table = arr_realloc(vlc->table, vlc->table_allocated,
+ sizeof(int16_t) * 2);
}
}
if (ret < 0)
goto out;
num_atts = ret;
- sl = para_realloc(sl, (2 * num_atts + 1) * sizeof(char *));
+ sl = arr_realloc(sl, 2 * num_atts + 1, sizeof(char *));
for (i = 0; i < num_atts; i++) {
char *orig = sl[i];
sl[i] = make_message("%s+", orig);
goto free_decoder;
if (c >= chunk_table_size) {
chunk_table_size = 2 * chunk_table_size + 100;
- afhi->chunk_table = para_realloc(afhi->chunk_table,
- chunk_table_size * sizeof(uint32_t));
+ afhi->chunk_table = arr_realloc(afhi->chunk_table,
+ chunk_table_size, sizeof(uint32_t));
}
afhi->chunk_table[c] = pos;
match_count++;
if (match_count >= matches_len) {
matches_len *= 2;
- matches = para_realloc(matches,
- matches_len * sizeof(char *));
+ matches = arr_realloc(matches, matches_len,
+ sizeof(char *));
}
matches[match_count - 1] = para_strdup(*p);
}
if (statistics.num >= aa->size) {
aa->size *= 2;
aa->size += 100;
- aa->array = para_realloc(aa->array,
- aa->size * sizeof(struct osl_row *));
+ aa->array = arr_realloc(aa->array, aa->size,
+ sizeof(struct osl_row *));
}
aa->array[statistics.num] = aft_row;
return add_afs_statistics(aft_row);
total_time = tmp;
if (afhi->chunks_total >= chunk_table_size) {
chunk_table_size *= 2;
- afhi->chunk_table = para_realloc(afhi->chunk_table,
- chunk_table_size * sizeof(uint32_t));
+ afhi->chunk_table = arr_realloc(afhi->chunk_table,
+ chunk_table_size, sizeof(uint32_t));
}
afhi->chunk_table[afhi->chunks_total] = fpos;
afhi->chunks_total++;
j++;
if (j >= ct_size) {
ct_size *= 2;
- afhi->chunk_table = para_realloc(
+ afhi->chunk_table = arr_realloc(
afhi->chunk_table,
- ct_size * sizeof(uint32_t));
+ ct_size, sizeof(uint32_t));
}
afhi->chunk_table[j] = oss.returned;
}
#include "string.h"
#include "error.h"
+/**
+ * Reallocate an array, abort on failure or bugs.
+ *
+ * \param ptr Pointer to the memory block, may be NULL.
+ * \param nmemb Number of elements.
+ * \param size The size of one element in bytes.
+ *
+ * A wrapper for realloc(3) which aborts on invalid arguments or integer
+ * overflow. The wrapper also terminates the current process on allocation
+ * errors, so the caller does not need to check for failure.
+ *
+ * \return A pointer to newly allocated memory which is suitably aligned for
+ * any kind of variable and may be different from ptr.
+ *
+ * \sa realloc(3).
+ */
+__must_check void *arr_realloc(void *ptr, size_t nmemb, size_t size)
+{
+ size_t pr;
+
+ assert(size > 0);
+ assert(nmemb > 0);
+ assert(!__builtin_mul_overflow(nmemb, size, &pr));
+ assert(pr != 0);
+ ptr = realloc(ptr, pr);
+ assert(ptr);
+ return ptr;
+}
+
/**
* Paraslash's version of realloc().
*
*/
__must_check void *para_realloc(void *p, size_t size)
{
- /*
- * No need to check for NULL pointers: If p is NULL, the call
- * to realloc is equivalent to malloc(size)
- */
- assert(size);
- if (!(p = realloc(p, size))) {
- PARA_EMERG_LOG("realloc failed (size = %zu), aborting\n",
- size);
- exit(EXIT_FAILURE);
- }
- return p;
+ return arr_realloc(p, 1, size);
}
/**
goto err;
if (!ret)
break;
- argv = para_realloc(argv, (i + 2) * sizeof(char*));
+ argv = arr_realloc(argv, i + 2, sizeof(char*));
argv[i] = word;
}
argv[i] = NULL;
} \
)
+__must_check void *arr_realloc(void *ptr, size_t nmemb, size_t size);
__must_check void *para_realloc(void *p, size_t size);
__must_check __malloc void *alloc(size_t size);
__must_check __malloc void *zalloc(size_t size);
git clone git://git.tuebingen.mpg.de/lopsub
- [gcc](ftp://ftp.gnu.org/pub/gnu/gcc) or
-[clang](http://clang.llvm.org). All gcc versions >= 4.2 are currently
-supported. Clang version 1.1 or newer should work as well.
+[clang](http://clang.llvm.org). All gcc versions >= 5.4 are currently
+supported. Moderately recent versions of clang should work as well.
- [gnu make](ftp://ftp.gnu.org/pub/gnu/make) is also shipped with the
disto. On BSD systems the gnu make executable is often called gmake.