[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] tcc_relocate() and tcc_relocate_ex()
From: |
Sean Conner |
Subject: |
Re: [Tinycc-devel] tcc_relocate() and tcc_relocate_ex() |
Date: |
Mon, 13 Aug 2012 16:53:16 -0400 |
User-agent: |
Mutt/1.4.1i |
It was thus said that the Great grischka once stated:
> Sean Conner wrote:
> >>As to the patch I think that
> >> + s1->runtime_mem = NULL;
> >>would break tcc_relocate and I don't see why you need it.
> >
> > I did that so that the call to tcc_delete() wouldn't crash when it tried
> >to free s->runtime_mem that might contain a garbage value (since
> >tcc_relocate_ex() would never set that field). Good thing too, because
> >tcc_new() *might not* be initializing NULL pointers correctly [1].
>
> Well, from my point of view that line would not fix tcc_new
> but cause a memory leak for tcc_relocate.
I did a bit more work. The assignment of s1->runtime_mem to NULL does not
lead to any memory leaks. On systems where the NULL pointer *is* all zeros
(most, if not all, modern systems I am aware of) removing the assignment
does not cause a crash (since the memory used to store the state is zeroed
out). On systems where the NULL pointer *IS NOT* all zeros [1], removing
the assignment *WILL CRASH*. Not "might crash", *WILL CRASH*. [2]
-spc
[1] Remember, ANSI C states that a literal 0 in the source code in a
pointer context is converted to a "NULL" pointer. Said "NULL"
pointer does not have to be 0.
[2] Okay, so I had to force the issue by hanging the assignment to a
bogus address that was not 0.
- [Tinycc-devel] tcc_relocate() and tcc_relocate_ex(), Sean Conner, 2012/08/09
- Re: [Tinycc-devel] tcc_relocate() and tcc_relocate_ex(), Thomas Preud'homme, 2012/08/11
- Re: [Tinycc-devel] tcc_relocate() and tcc_relocate_ex(), Sean Conner, 2012/08/11
- Re: [Tinycc-devel] tcc_relocate() and tcc_relocate_ex(), grischka, 2012/08/12
- Re: [Tinycc-devel] tcc_relocate() and tcc_relocate_ex(), Sean Conner, 2012/08/13
- Re: [Tinycc-devel] tcc_relocate() and tcc_relocate_ex(), grischka, 2012/08/13
- Re: [Tinycc-devel] tcc_relocate() and tcc_relocate_ex(), Sean Conner, 2012/08/13
- Re: [Tinycc-devel] tcc_relocate() and tcc_relocate_ex(),
Sean Conner <=
- Re: [Tinycc-devel] tcc_relocate() and tcc_relocate_ex(), grischka, 2012/08/14
- Re: [Tinycc-devel] tcc_relocate() and tcc_relocate_ex(), Sean Conner, 2012/08/22
- Re: [Tinycc-devel] tcc_relocate() and tcc_relocate_ex(), grischka, 2012/08/23
- Re: [Tinycc-devel] tcc_relocate() and tcc_relocate_ex(), Sean Conner, 2012/08/23
- Re: [Tinycc-devel] tcc_relocate() and tcc_relocate_ex(), grischka, 2012/08/24
- Re: [Tinycc-devel] tcc_relocate() and tcc_relocate_ex(), Sean Conner, 2012/08/24
- Re: [Tinycc-devel] tcc_relocate() and tcc_relocate_ex(), grischka, 2012/08/27
- Re: [Tinycc-devel] tcc_relocate() and tcc_relocate_ex(), Sean Conner, 2012/08/28
- Re: [Tinycc-devel] tcc_relocate() and tcc_relocate_ex(), David Mertens, 2012/08/28
- Re: [Tinycc-devel] tcc_relocate() and tcc_relocate_ex(), Michael Matz, 2012/08/28