From mboxrd@z Thu Jan 1 00:00:00 1970 From: "mail-lists" Subject: RE: malloc with size 0 Date: Fri, 30 Dec 2005 14:16:35 -0000 Message-ID: <200512301423.jBUENrJ12120@stev.org> References: <1f5f62170512212043w17e1c8e7v3781e0dc72845efc@mail.gmail.com> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1f5f62170512212043w17e1c8e7v3781e0dc72845efc@mail.gmail.com> Sender: linux-c-programming-owner@vger.kernel.org List-Id: Content-Type: text/plain; charset="us-ascii" To: 'Suma C' , 'C programming list' Hi, This was a strange problem I came across about 2 years ago. Some systems return NULL some return a valid result. I would treat it as a case where you would not try to alloc a size of 0 its kind of unpredictable depending on lib version and which system your on. James > -----Original Message----- > From: linux-c-programming-owner@vger.kernel.org [mailto:linux-c- > programming-owner@vger.kernel.org] On Behalf Of Suma C > Sent: 22 December 2005 04:44 > To: C programming list > Subject: malloc with size 0 > > Hi all > > When a 0 is passed to malloc, I get a valid pointer instead of a NULL > .What does this mean? > > thanks in advance > > regards > suma > > PS: > code: > #include > #include > > int main() > { > char *ptr = NULL; > ptr = malloc(0); > printf("ptr :%u \n",ptr); > strcpy(ptr,"abcdefghijkl"); > printf("%s\n",ptr); //no seg fault here???? > return 0; > } > - > To unsubscribe from this list: send the line "unsubscribe linux-c- > programming" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html