- Subject: malloc question
- From: Randi Botse <nightdecoder@xxxxxxxxx>
- Date: Tue, 26 Apr 2011 17:33:50 +0700
- List-id: <linux-c-programming.vger.kernel.org>
Hi All,
I want to ask malloc() behaviour, consider these codes;
...
char *ptr = malloc(1);
strcpy(ptr, "what");
puts(ptr);
....
Confusingly, the strcpy() copied all bytes to ptr, but I just manage
to allocate ptr only for 1 byte, I guess I will have segfault here,
why this happen? why the string successfully copied into ptr? , is
those code legal?
Randi,
--
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
[Linux Assembler]
[Git]
[Kernel List]
[Fedora Development]
[Fedora Announce]
[Autoconf]
[Yosemite Campsites]
[Yosemite News]
[GCC Help]