...
Code Block |
---|
size_t num_elements = calc_size();
long *buffer = calloc(num_elements, sizeof(long));
if ((num_elements*sizeof(long)) >= (SIZE_MAX>>1)) {
/* Handle error condition*/
}
else {
/* Handle error condition */
}
|
References
RUS-CERT Advisory 2002-08:02, http://cert.uni-stuttgart.de/advisories/calloc.php
Secunia Advisory SA10635, http://secunia.com/advisories/10635/
ISO/IEC 9899, 7.18.3 Limits of other integer types