Re: malloc(1/0) ??

2000-11-09 Thread Igmar Palsenberg
> Where the heck did you get idea? By reading the man page in the middle of the night and reading realloc() as malloc(). My error. > -hpa Igmar - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read

Re: malloc(1/0) ??

2000-11-09 Thread Igmar Palsenberg
Where the heck did you get idea? By reading the man page in the middle of the night and reading realloc() as malloc(). My error. -hpa Igmar - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] Please read

Re: malloc(1/0) ??

2000-11-08 Thread Rasmus Andersen
On Wed, Nov 08, 2000 at 02:11:34PM -0800, H. Peter Anvin wrote: > Followup to: <[EMAIL PROTECTED]> > By author:Igmar Palsenberg <[EMAIL PROTECTED]> > In newsgroup: linux.dev.kernel [snip] > > May I remind you guys that a malloc(0) is equal to a free(). There is no > > way that any mem

Re: malloc(1/0) ??

2000-11-08 Thread H. Peter Anvin
Followup to: <[EMAIL PROTECTED]> By author:Igmar Palsenberg <[EMAIL PROTECTED]> In newsgroup: linux.dev.kernel > > > > The program does not work. A program works if it does what it's supposed to > > do. If you want to argue that this program is supposed to print "ff" > > then

Re: malloc(1/0) ??

2000-11-08 Thread Igmar Palsenberg
On Tue, 7 Nov 2000, Tim Waugh wrote: > On Wed, Nov 08, 2000 at 01:41:40AM +0100, Igmar Palsenberg wrote: > > > malloc(0) is bogus in this case. malloc(0) == free(); > > No, you're thinking of realloc. Yep. My error. Sorry. Igmar - To unsubscribe from this list: send the line

Re: malloc(1/0) ??

2000-11-08 Thread Igmar Palsenberg
On Tue, 7 Nov 2000, Tim Waugh wrote: On Wed, Nov 08, 2000 at 01:41:40AM +0100, Igmar Palsenberg wrote: malloc(0) is bogus in this case. malloc(0) == free(); No, you're thinking of realloc. Yep. My error. Sorry. Igmar - To unsubscribe from this list: send the line "unsubscribe

Re: malloc(1/0) ??

2000-11-08 Thread H. Peter Anvin
Followup to: [EMAIL PROTECTED] By author:Igmar Palsenberg [EMAIL PROTECTED] In newsgroup: linux.dev.kernel The program does not work. A program works if it does what it's supposed to do. If you want to argue that this program is supposed to print "ff" then explain to me why

Re: malloc(1/0) ??

2000-11-08 Thread Rasmus Andersen
On Wed, Nov 08, 2000 at 02:11:34PM -0800, H. Peter Anvin wrote: Followup to: [EMAIL PROTECTED] By author:Igmar Palsenberg [EMAIL PROTECTED] In newsgroup: linux.dev.kernel [snip] May I remind you guys that a malloc(0) is equal to a free(). There is no way that any mem get's malloced.

Re: malloc(1/0) ??

2000-11-07 Thread Tim Waugh
On Wed, Nov 08, 2000 at 01:41:40AM +0100, Igmar Palsenberg wrote: > malloc(0) is bogus in this case. malloc(0) == free(); No, you're thinking of realloc. Tim. */ PGP signature

RE: malloc(1/0) ??

2000-11-07 Thread David Schwartz
> This way all should work. However someone mentioned that the returns > from "malloc" should be unique. Why would that be? That would prohibit > my "1" trick. The statement implies you want to go about checking > pointers for equality. If for example you have a memcmp (a, b) that > has "if (a

Re: malloc(1/0) ??

2000-11-07 Thread Rogier Wolff
Matti Aarnio wrote: > needed size is bound to get user burned. malloc(0) is insane thing > (IMO), but at least glibc supports it for some reason. Likely just due > to padding and minimum size issues. Part of the desing of the C language and the library is intended to make boundary conditions

Re: malloc(1/0) ??

2000-11-07 Thread Igmar Palsenberg
On Tue, 7 Nov 2000, Lyle Coder wrote: > When a program does a malloc... the glibc gets atleast on page (brk) > [actually, glibs determins of it needs to brk more memory from the kernel... > because it maintains it;s own pool].. so if you malloc 4 byts, you can copy > to that pointer more than 4

RE: malloc(1/0) ??

2000-11-07 Thread Igmar Palsenberg
> The program does not work. A program works if it does what it's supposed to > do. If you want to argue that this program is supposed to print "ff" > then explain to me why the 'malloc' contains a zero in parenthesis. > > The program can't possibly work because it invokes

Re: malloc(1/0) ??

2000-11-07 Thread Igmar Palsenberg
> I'm not sure that is fully responsive, Dan. Why doesn't the > strcpy throw a hissyfit and coredump? Because he's a lucky guy and doesn't cross a page boundary. If the "" thing is the entire Wind95 source code it will dump :-) > {^_^} Igmar - To unsubscribe from this list: send

Re: malloc(1/0) ??

2000-11-07 Thread Igmar Palsenberg
On Mon, 6 Nov 2000, RAJESH BALAN wrote: > hi, > why does this program works. when executed, it doesnt > give a segmentation fault. when the program requests > memory, is a standard chunk is allocated irrespective > of the what the user specifies. please explain. > > main() > { >char *s; >

RE: malloc(1/0) ??

2000-11-07 Thread lost
> > > main() > > > { > > >char *s; > > >s = (char*)malloc(0); > > >strcpy(s,"f"); > > >printf("%s\n",s); > > > } I rather suspect that the strcpy() scribbled over malloc()s record keeping data. However, that memory was in the processes allowed address space so it didn't

RE: malloc(1/0) ??

2000-11-07 Thread Jesse Pollard
> > > hi, > > why does this program works. when executed, it doesnt > > give a segmentation fault. when the program requests > > memory, is a standard chunk is allocated irrespective > > of the what the user specifies. please explain. > > > > main() > > { > >char *s; > >s =

RE: malloc (1/0) ??

2000-11-07 Thread David Feuer
As long as you don't try to do any more mm once you've allocated with malloc(0), and as long as you haven't done any previous allocations with malloc, you should be able to scribble all over malloc. In fact, if you want, I think you can scribble all over your own stack without causing Linux

RE: malloc(1/0) ??

2000-11-07 Thread David Schwartz
> > The program can't possibly work because it invokes undefined > behavior. It > > is impossible to determine what a program that invokes > undefined behavior is > > 'supposed to do'. > > I dont think it's undefined behaviour ... You are correct. This is bahavior that is undefined by

Re: malloc(1/0) ??

2000-11-07 Thread Matti Aarnio
On Tue, Nov 07, 2000 at 12:09:09AM -0800, Lyle Coder wrote: > When a program does a malloc... the glibc gets atleast on page (brk) > [actually, glibs determins of it needs to brk more memory from the kernel... > because it maintains it;s own pool].. so if you malloc 4 byts, you can copy > to that

RE: malloc(1/0) ??

2000-11-07 Thread Andrej Hosna
Hello , > > why does this program works. when executed, it doesnt > > give a segmentation fault. when the program requests > > memory, is a standard chunk is allocated irrespective > > of the what the user specifies. please explain. > > > > main() > > { > >char *s; > >s =

Re: malloc(1/0) ??

2000-11-07 Thread Lyle Coder
that answers one of your questions... as far as why malloc(0) works... I dunno Best Wishes, Lyle - Original Message - From: "David Schwartz" <[EMAIL PROTECTED]> To: "RAJESH BALAN" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Monday, November 06, 2000 11:54 P

RE: malloc (1/0) ??

2000-11-07 Thread David Feuer
As long as you don't try to do any more mm once you've allocated with malloc(0), and as long as you haven't done any previous allocations with malloc, you should be able to scribble all over malloc. In fact, if you want, I think you can scribble all over your own stack without causing Linux

RE: malloc(1/0) ??

2000-11-07 Thread Jesse Pollard
hi, why does this program works. when executed, it doesnt give a segmentation fault. when the program requests memory, is a standard chunk is allocated irrespective of the what the user specifies. please explain. main() { char *s; s = (char*)malloc(0);

RE: malloc(1/0) ??

2000-11-07 Thread lost
main() { char *s; s = (char*)malloc(0); strcpy(s,"f"); printf("%s\n",s); } I rather suspect that the strcpy() scribbled over malloc()s record keeping data. However, that memory was in the processes allowed address space so it didn't SIGSEGV. Now, when you

Re: malloc(1/0) ??

2000-11-07 Thread Igmar Palsenberg
On Mon, 6 Nov 2000, RAJESH BALAN wrote: hi, why does this program works. when executed, it doesnt give a segmentation fault. when the program requests memory, is a standard chunk is allocated irrespective of the what the user specifies. please explain. main() { char *s; s =

Re: malloc(1/0) ??

2000-11-07 Thread Igmar Palsenberg
I'm not sure that is fully responsive, Dan. Why doesn't the strcpy throw a hissyfit and coredump? Because he's a lucky guy and doesn't cross a page boundary. If the "" thing is the entire Wind95 source code it will dump :-) {^_^} Igmar - To unsubscribe from this list: send

RE: malloc(1/0) ??

2000-11-07 Thread Igmar Palsenberg
The program does not work. A program works if it does what it's supposed to do. If you want to argue that this program is supposed to print "ff" then explain to me why the 'malloc' contains a zero in parenthesis. The program can't possibly work because it invokes undefined

Re: malloc(1/0) ??

2000-11-07 Thread Igmar Palsenberg
On Tue, 7 Nov 2000, Lyle Coder wrote: When a program does a malloc... the glibc gets atleast on page (brk) [actually, glibs determins of it needs to brk more memory from the kernel... because it maintains it;s own pool].. so if you malloc 4 byts, you can copy to that pointer more than 4

Re: malloc(1/0) ??

2000-11-07 Thread Rogier Wolff
Matti Aarnio wrote: needed size is bound to get user burned. malloc(0) is insane thing (IMO), but at least glibc supports it for some reason. Likely just due to padding and minimum size issues. Part of the desing of the C language and the library is intended to make boundary conditions go

RE: malloc(1/0) ??

2000-11-07 Thread David Schwartz
This way all should work. However someone mentioned that the returns from "malloc" should be unique. Why would that be? That would prohibit my "1" trick. The statement implies you want to go about checking pointers for equality. If for example you have a memcmp (a, b) that has "if (a == b)

Re: malloc(1/0) ??

2000-11-07 Thread Tim Waugh
On Wed, Nov 08, 2000 at 01:41:40AM +0100, Igmar Palsenberg wrote: malloc(0) is bogus in this case. malloc(0) == free(); No, you're thinking of realloc. Tim. */ PGP signature

RE: malloc(1/0) ??

2000-11-06 Thread David Schwartz
> hi, > why does this program works. when executed, it doesnt > give a segmentation fault. when the program requests > memory, is a standard chunk is allocated irrespective > of the what the user specifies. please explain. > > main() > { >char *s; >s = (char*)malloc(0); >

RE: malloc(1/0) ??

2000-11-06 Thread David Schwartz
> From: "Dan Kegel" <[EMAIL PROTECTED]> > > [EMAIL PROTECTED] asked: > > > [Why does this program not crash?] > > > > > > main() > > > { > > >char *s; > > >s = (char*)malloc(0); > > >strcpy(s,"f"); > > >printf("%s\n",s); > > > } > > > > It doesn't crash because the standard

Re: malloc(1/0) ??

2000-11-06 Thread J. Dow
From: "Dan Kegel" <[EMAIL PROTECTED]> > [EMAIL PROTECTED] asked: > > [Why does this program not crash?] > > > > main() > > { > >char *s; > >s = (char*)malloc(0); > >strcpy(s,"f"); > >printf("%s\n",s); > > } > > It doesn't crash because the standard malloc is >

Re: malloc(1/0) ??

2000-11-06 Thread Dan Kegel
[EMAIL PROTECTED] asked: > [Why does this program not crash?] > > main() > { >char *s; >s = (char*)malloc(0); >strcpy(s,"f"); >printf("%s\n",s); > } It doesn't crash because the standard malloc is optimized for speed, not for finding bugs. Try linking it with a

malloc(1/0) ??

2000-11-06 Thread RAJESH BALAN
hi, why does this program works. when executed, it doesnt give a segmentation fault. when the program requests memory, is a standard chunk is allocated irrespective of the what the user specifies. please explain. main() { char *s; s = (char*)malloc(0); strcpy(s,"f");

malloc(1/0) ??

2000-11-06 Thread RAJESH BALAN
hi, why does this program works. when executed, it doesnt give a segmentation fault. when the program requests memory, is a standard chunk is allocated irrespective of the what the user specifies. please explain. main() { char *s; s = (char*)malloc(0); strcpy(s,"f");