You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
malloc(n * size) is an antipattern as n * size can overflow (especially from an attacker). You'll want to use calloc or create your own malloc_array function. Something like the following could work:
staticinlinevoid*malloc_array(size_tnmemb, size_tsize)
{
/* Make the check so that a constant size deletes the zero check * and the division. */if (size!=0u&&SIZE_MAX / size<nmemb) {
errno=ENOMEM;
returnNULL;
}
returnmalloc(size*nmemb);
}
The text was updated successfully, but these errors were encountered:
malloc(n * size)
is an antipattern asn * size
can overflow (especially from an attacker). You'll want to usecalloc
or create your ownmalloc_array
function. Something like the following could work:The text was updated successfully, but these errors were encountered: