linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "mail-lists" <mail-lists@stev.org>
To: 'Suma C' <gsumac@gmail.com>,
	'C programming list' <linux-c-programming@vger.kernel.org>
Subject: RE: malloc with size 0
Date: Fri, 30 Dec 2005 14:16:35 -0000	[thread overview]
Message-ID: <200512301423.jBUENrJ12120@stev.org> (raw)
In-Reply-To: <1f5f62170512212043w17e1c8e7v3781e0dc72845efc@mail.gmail.com>

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 <stdio.h>
> #include <stdlib.h>
> 
> 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



      parent reply	other threads:[~2005-12-30 14:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-12-22  4:43 malloc with size 0 Suma C
2005-12-22  6:21 ` Hareesh Nagarajan
2005-12-22  7:42   ` Suma C
2005-12-22 13:02 ` Neil Horman
2005-12-30 14:16 ` mail-lists [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200512301423.jBUENrJ12120@stev.org \
    --to=mail-lists@stev.org \
    --cc=gsumac@gmail.com \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).