-
Notifications
You must be signed in to change notification settings - Fork 140
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
Memory error with macros with arguments #434
Labels
bug
Something isn't working
Comments
The following patch makes this problem manifest and gives a segfault. diff --git a/sources/tools.c b/sources/tools.c
index 3279d07..f392291 100644
--- a/sources/tools.c
+++ b/sources/tools.c
@@ -2788,7 +2788,15 @@ VOID *FromList(LIST *L)
i = ( L->num * L->size ) / sizeof(int);
old = (int *)L->lijst; newL = (int *)newlist;
while ( --i >= 0 ) *newL++ = *old++;
- if ( L->lijst ) M_free(L->lijst,"L->lijst FromList");
+ if ( L->lijst ) {
+ // Before freeing the memory block, we mess up its content.
+ // This must not be a problem.
+ char *p = (char *)L->lijst;
+ for (int i = 0; i < L->num * L->size; i++) {
+ *p++ = 'x'; // non-zero
+ }
+ M_free(L->lijst,"L->lijst FromList");
+ }
}
L->lijst = newlist;
} |
When Lines 370 to 381 in 6cc038c
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is found during the discussion of #433. The following code leads to a Valgrind error with the current master branch:
The point is that the$12 \times 2^n - 1$ with $n \in \mathbb{Z}_{\ge0}$ . The magic number 12 comes from how the
var
macro has the index 23, which isFromList
function extends the list (the initial capacity is 12; the comment says 10 but that is wrong).The text was updated successfully, but these errors were encountered: