if (fg->num_slices == 0) {
fg->num_slices = fg->h.slices_per_group;
fg->idx = arr_alloc(fg->num_slices, sizeof(int));
- fg->data = zalloc(fg->num_slices * sizeof(unsigned char *));
+ fg->data = arr_zalloc(fg->num_slices, sizeof(unsigned char *));
}
r = fg->num_received_slices;
/* Check if we already have this slice. */
session_open();
num_inputs = lls_num_inputs(play_lpr);
init_shuffle_map();
- pt->invalid = zalloc(sizeof(*pt->invalid) * num_inputs);
+ pt->invalid = arr_zalloc(num_inputs, sizeof(*pt->invalid));
pt->rq = CRT_FILE_CHANGE;
pt->playing = true;
pt->task = task_register(&(struct task_info){
return arr_realloc(NULL, nmemb, size);
}
+/**
+ * Allocate and initialize an array, abort on failure or bugs.
+ *
+ * \param nmemb See \ref arr_realloc().
+ * \param size See \ref arr_realloc().
+ *
+ * This calls \ref arr_alloc() and zeroes-out the array.
+ *
+ * \return See \ref arr_alloc().
+ */
+__must_check __malloc void *arr_zalloc(size_t nmemb, size_t size)
+{
+ void *ptr = arr_alloc(nmemb, size);
+
+ /*
+ * This multiplication can not overflow because the above call to \ref
+ * arr_alloc() aborts on overflow.
+ */
+ memset(ptr, 0, nmemb * size);
+ return ptr;
+}
+
+/**
+ * Allocate and initialize memory.
+ *
+ * \param size The desired new size.
+ *
+ * \return A pointer to the allocated and zeroed-out memory, which is suitably
+ * aligned for any kind of variable.
+ *
+ * \sa \ref alloc(), calloc(3).
+ */
+__must_check void *zalloc(size_t size)
+{
+ return arr_zalloc(1, size);
+}
+
/**
* Paraslash's version of realloc().
*
return arr_alloc(1, size);
}
-/**
- * Allocate and initialize memory.
- *
- * \param size The desired new size.
- *
- * \return A pointer to the allocated and zeroed-out memory, which is suitably
- * aligned for any kind of variable.
- *
- * \sa \ref alloc(), calloc(3).
- */
-__must_check __malloc void *zalloc(size_t size)
-{
- void *ret = alloc(size);
-
- memset(ret, 0, size);
- return ret;
-}
-
/**
* Paraslash's version of strdup().
*
__must_check __malloc void *alloc(size_t size);
__must_check __malloc void *zalloc(size_t size);
__must_check __malloc void *arr_alloc(size_t nmemb, size_t size);
+__must_check __malloc void *arr_zalloc(size_t nmemb, size_t size);
__must_check __malloc char *para_strdup(const char *s);
__printf_2_0 unsigned xvasprintf(char **result, const char *fmt, va_list ap);
}, &s);
n = writer_given? writer_given : 1;
- wns = zalloc(n * sizeof(*wns));
+ wns = arr_zalloc(n, sizeof(*wns));
for (i = 0; i < n; i++) {
const char *arg = i < writer_given?
lls_string_val(i, OPT_RESULT(WRITER, lpr)) : NULL;