9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] memory bug in 5l
@ 2014-12-10  0:21 yoann padioleau
  2014-12-10  0:24 ` yoann padioleau
  2014-12-10  1:19 ` yoann padioleau
  0 siblings, 2 replies; 6+ messages in thread
From: yoann padioleau @ 2014-12-10  0:21 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

in 5l/obj.c#zaddr()
there is:
	case D_FCONST:
		while(nhunk < sizeof(Ieee))
			gethunk();
		a->ieee = (Ieee*)hunk;
		nhunk -= NSNAME;
		hunk += NSNAME;

I think it’s a copy paste bug, it should
be sizeof(Ieee) instead of those NSNAME
(or even better the whole code could be factorized
in a call to a->ieee = malloc(sizeof(Ieee));




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] memory bug in 5l
  2014-12-10  0:21 [9fans] memory bug in 5l yoann padioleau
@ 2014-12-10  0:24 ` yoann padioleau
  2014-12-10  1:35   ` Steve Simon
  2014-12-10  1:19 ` yoann padioleau
  1 sibling, 1 reply; 6+ messages in thread
From: yoann padioleau @ 2014-12-10  0:24 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Also, by curiosity, does anybody know why 5a/, 5l/, 5c/
(and the other architecture variants) are redefining
malloc and free? Why not using the malloc and free
from the libc?


On Dec 9, 2014, at 4:21 PM, yoann padioleau <aryx.padator@gmail.com> wrote:

> in 5l/obj.c#zaddr()
> there is:
> 	case D_FCONST:
> 		while(nhunk < sizeof(Ieee))
> 			gethunk();
> 		a->ieee = (Ieee*)hunk;
> 		nhunk -= NSNAME;
> 		hunk += NSNAME;
> 
> I think it’s a copy paste bug, it should
> be sizeof(Ieee) instead of those NSNAME
> (or even better the whole code could be factorized
> in a call to a->ieee = malloc(sizeof(Ieee));
> 




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] memory bug in 5l
  2014-12-10  0:21 [9fans] memory bug in 5l yoann padioleau
  2014-12-10  0:24 ` yoann padioleau
@ 2014-12-10  1:19 ` yoann padioleau
  2014-12-10 10:07   ` Charles Forsyth
  1 sibling, 1 reply; 6+ messages in thread
From: yoann padioleau @ 2014-12-10  1:19 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

There is a related bug still in this file in ldobj() I think:

	if(nhunk < sizeof(Prog))
		gethunk();
	p = (Prog*)hunk;
	nhunk -= sizeof(Prog);
	hunk += sizeof(Prog);

it should be while(chunk < sizeof(Prog))
(or even better again, a simple call to malloc(sizeof(Prog))


On Dec 9, 2014, at 4:21 PM, yoann padioleau <aryx.padator@gmail.com> wrote:

> in 5l/obj.c#zaddr()
> there is:
> 	case D_FCONST:
> 		while(nhunk < sizeof(Ieee))
> 			gethunk();
> 		a->ieee = (Ieee*)hunk;
> 		nhunk -= NSNAME;
> 		hunk += NSNAME;
> 
> I think it’s a copy paste bug, it should
> be sizeof(Ieee) instead of those NSNAME
> (or even better the whole code could be factorized
> in a call to a->ieee = malloc(sizeof(Ieee));
> 




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] memory bug in 5l
  2014-12-10  0:24 ` yoann padioleau
@ 2014-12-10  1:35   ` Steve Simon
  0 siblings, 0 replies; 6+ messages in thread
From: Steve Simon @ 2014-12-10  1:35 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

the compilers use a very simple allocator which is designed for speed
rather than efficiency - as i remember it never frees anything and just
allocates from a heap.

it also works if you use libc's malloc and that will allow you to link big things
(like gs) on small memory machines. in reality memory is cheap and no one
likes to wait when they don't have to.

-Steve



> On 10 Dec 2014, at 00:24, yoann padioleau <aryx.padator@gmail.com> wrote:
> 
> Also, by curiosity, does anybody know why 5a/, 5l/, 5c/
> (and the other architecture variants) are redefining
> malloc and free? Why not using the malloc and free
> from the libc?
> 
> 
>> On Dec 9, 2014, at 4:21 PM, yoann padioleau <aryx.padator@gmail.com> wrote:
>> 
>> in 5l/obj.c#zaddr()
>> there is:
>>   case D_FCONST:
>>       while(nhunk < sizeof(Ieee))
>>           gethunk();
>>       a->ieee = (Ieee*)hunk;
>>       nhunk -= NSNAME;
>>       hunk += NSNAME;
>> 
>> I think it’s a copy paste bug, it should
>> be sizeof(Ieee) instead of those NSNAME
>> (or even better the whole code could be factorized
>> in a call to a->ieee = malloc(sizeof(Ieee));
> 



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] memory bug in 5l
  2014-12-10  1:19 ` yoann padioleau
@ 2014-12-10 10:07   ` Charles Forsyth
  2014-12-15 21:20     ` yoann padioleau
  0 siblings, 1 reply; 6+ messages in thread
From: Charles Forsyth @ 2014-12-10 10:07 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 204 bytes --]

On Wed, Dec 10, 2014 at 1:19 AM, yoann padioleau <aryx.padator@gmail.com>
wrote:

> it should be while(chunk < sizeof(Prog))


a hunk is always much bigger than sizeof(Prog) so it's the same as if

[-- Attachment #2: Type: text/html, Size: 497 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [9fans] memory bug in 5l
  2014-12-10 10:07   ` Charles Forsyth
@ 2014-12-15 21:20     ` yoann padioleau
  0 siblings, 0 replies; 6+ messages in thread
From: yoann padioleau @ 2014-12-15 21:20 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

[-- Attachment #1: Type: text/plain, Size: 467 bytes --]

Right, but the same code in 8l does the while
loop, and most of the code in 5l does the while loop,
so for consistency it seems it should also be a while loop
here.


On Dec 10, 2014, at 2:07 AM, Charles Forsyth <charles.forsyth@gmail.com> wrote:

> 
> On Wed, Dec 10, 2014 at 1:19 AM, yoann padioleau <aryx.padator@gmail.com> wrote:
> it should be while(chunk < sizeof(Prog))
> 
> a hunk is always much bigger than sizeof(Prog) so it's the same as if


[-- Attachment #2: Type: text/html, Size: 1154 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-12-15 21:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-10  0:21 [9fans] memory bug in 5l yoann padioleau
2014-12-10  0:24 ` yoann padioleau
2014-12-10  1:35   ` Steve Simon
2014-12-10  1:19 ` yoann padioleau
2014-12-10 10:07   ` Charles Forsyth
2014-12-15 21:20     ` yoann padioleau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).