+static bool adjust_size(size_t *size, size_t count)
+{
+ const size_t extra = sizeof(struct tal_hdr) + sizeof(struct length)*2;
+
+ /* Multiplication wrap */
+ if (count && unlikely(*size * count / *size != count))
+ goto overflow;
+
+ *size *= count;
+
+ /* Make sure we don't wrap adding header/tailer. */
+ if (*size + extra < extra)
+ goto overflow;
+ return true;
+overflow:
+ call_error("allocation size overflow");
+ return false;
+}
+
+void *tal_alloc_arr_(const tal_t *ctx, size_t size, size_t count, bool clear,
+ bool add_length, const char *label)
+{
+ if (!adjust_size(&size, count))
+ return NULL;
+
+ return tal_alloc_(ctx, size, clear, add_length, label);
+}
+