Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Memory Sanitation Incompatibility #356

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/check_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,18 @@ void *emalloc(size_t n)
p = malloc(n);
if(p == NULL)
eprintf("malloc of " CK_FMT_ZU " bytes failed:", __FILE__, __LINE__ - 2, n);
memset(p, 0xAA, n);
return p;
}

void *erealloc(void *ptr, size_t n)
void *erealloc(void *ptr, size_t old_n, size_t n)
{
void *p;

p = realloc(ptr, n);
if(p == NULL)
eprintf("realloc of " CK_FMT_ZU " bytes failed:", __FILE__, __LINE__ - 2, n);
if(n > old_n)
memset(p+old_n, 0xAA, n-old_n);
return p;
}
2 changes: 1 addition & 1 deletion src/check_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ void eprintf(const char *fmt, const char *file, int line,
...) CK_ATTRIBUTE_NORETURN CK_ATTRIBUTE_FORMAT(printf, 1, 4);
/* malloc or die */
void *emalloc(size_t n);
void *erealloc(void *, size_t n);
void *erealloc(void *, size_t old_n, size_t n);

#endif /*ERROR_H */
2 changes: 1 addition & 1 deletion src/check_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ static void maybe_grow(List * lp)
{
if(lp->n_elts >= lp->max_elts)
{
lp->data = (void **)erealloc(lp->data, lp->max_elts * sizeof(lp->data[0]), lp->max_elts * LGROW * sizeof(lp->data[0]));
lp->max_elts *= LGROW;
lp->data = (void **)erealloc(lp->data, lp->max_elts * sizeof(lp->data[0]));
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/check_str.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ char *ck_strdup_printf(const char *fmt, ...)
{
/* Guess we need no more than 100 bytes. */
size_t size = 100;
size_t new_size;
char *p;
va_list ap;

Expand All @@ -96,11 +97,12 @@ char *ck_strdup_printf(const char *fmt, ...)

/* Else try again with more space. */
if(n > -1) /* C99 conform vsnprintf() */
size = (size_t) n + 1; /* precisely what is needed */
new_size = (size_t) n + 1; /* precisely what is needed */
else /* glibc 2.0 */
size *= 2; /* twice the old size */
new_size *= 2; /* twice the old size */

p = (char *)erealloc(p, size);
p = (char *)erealloc(p, size, new_size);
size = new_size;
}
}

Expand Down