Project

Profile

Help

HostedRedmine.com has moved to the Planio platform. All logins and passwords remained the same. All users will be able to login and use Redmine just as before. *Read more...*

Feature #898114 ยป 0031-Improve-mem.c-coding-style.patch

Marko Lindqvist, 2020-11-17 08:40 PM

View differences:

utility/mem.c
{
log_fatal("Out of memory trying to %s %lu bytes at line %d of %s.",
called_as, (unsigned long) size, line, file);
exit(EXIT_FAILURE);
}
......
const char *called_as, int line, const char *file)
{
void *new_ptr;
if (!ptr) {
return fc_real_malloc(size, called_as, line, file);
}
......
if (!new_ptr) {
handle_alloc_failure(size, called_as, line, file);
}
return new_ptr;
}
......
No need to check return value.
I'm pretty sure only the product of nelem and elsize can ever
matter here, and not their individual values. (As a matter of C.)
matter here, and not their individual values. (As a matter of C.)
Except this function doesn't support calloc-ing more memory than
can be expressing using a single size_t, but that's not likely
to be a problem.
......
void *fc_real_calloc(size_t nelem, size_t elsize,
const char *called_as, int line, const char *file)
{
size_t size = nelem*elsize; /* potential overflow */
size_t size = nelem * elsize; /* potential overflow */
void *ptr;
ptr = fc_real_malloc(size, called_as, line, file);
memset(ptr, 0, size);
return ptr;
}
......
char *real_fc_strdup(const char *str,
const char *called_as, int line, const char *file)
{
char *dest = fc_real_malloc(strlen(str)+1, called_as, line, file);
char *dest = fc_real_malloc(strlen(str) + 1, called_as, line, file);
/* no need to check whether dest is non-NULL! */
/* No need to check whether dest is non-NULL! */
strcpy(dest, str);
return dest;
}
    (1-1/1)