klib icon indicating copy to clipboard operation
klib copied to clipboard

Introduce kreallocarray with overflow checking

Open ethomson opened this issue 9 years ago • 2 comments

Introduce a kreallocarray with overflow checking, with a signature equivalent to OpenBSD reallocarray(3). This prevents a realloc from appearing to succeed when new_n_buckets is larger than SIZE_MAX / sizeof(khkey_t) or SIZE_MAX / sizeof(khval_t).

ethomson avatar Feb 11 '15 22:02 ethomson

I think that - should be a /

-#define kreallocarray(P,N,Z) ((SIZE_MAX - N < Z) ? NULL : krealloc(P, (N*Z)))
+#define kreallocarray(P,N,Z) ((SIZE_MAX / N < Z) ? NULL : krealloc(P, (N*Z)))

noporpoise avatar Feb 16 '15 20:02 noporpoise

Thanks @noporpoise - that - should indeed be a /. Fixed!

ethomson avatar Feb 17 '15 14:02 ethomson