From: Marius Nita <marius@cs.pdx.edu>
To: Mohammed Khalid Ansari <khalid@ncst.ernet.in>
Cc: linux-c-programming@vger.kernel.org
Subject: Re: is it a buf or what?
Date: Sat, 8 Jun 2002 10:24:48 -0700 [thread overview]
Message-ID: <20020608102448.A1510@cs.pdx.edu> (raw)
In-Reply-To: <Pine.LNX.4.33.0206081601090.19134-100000@soochak.ncst.ernet.in>; from khalid@ncst.ernet.in on Sat, Jun 08, 2002 at 04:03:35PM +0530
On Sat, Jun 08, 2002 at 04:03:35PM +0530, Mohammed Khalid Ansari wrote:
>
> Hi,
>
> I had written a small program as follows...
>
> #include <stdio.h>
>
> int main()
> {
> char *ptr;
>
> strcpy (ptr, "khalid");
Try this with a larger string, say 400 bytes. It will most likely segfault.
Since your string is small, there's a high probability that ptr will be
pointing to a small chunk of writable memory, in which your 7 bytes happen to
fit.
> printf ("%s\n", ptr);
> return 0;
> }
>
> As you can see, I haven't allocated the space for the pointer ptr. When I
> ran the program, instead of giving me the segmentation fault, it just ran
> printing "khalid". Is it a bug of gcc or the kernel.
Neither. This is perfectly normal behavior.
> --
>
> **************************************************************************
>
> Mohammed Khalid Ansari Tel (res) : 0091-022-3051360
> Assistant Manager II (off) : 0091-022-2024641
> National Centre for Software Technology Fax : 0091-022-2049573
> 8th flr,Air India Build. Nariman Point, E-Mail : khalid@ncst.ernet.in
> Mumbai 400021.
>
> Homepage : http://soochak.ncst.ernet.in/~khalid
>
> **************************************************************************
>
> -
> 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
prev parent reply other threads:[~2002-06-08 17:24 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-06-08 10:33 is it a buf or what? Mohammed Khalid Ansari
2002-06-08 12:03 ` Glynn Clements
2002-06-08 16:40 ` Elias Athanasopoulos
2002-06-08 17:24 ` Marius Nita [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=20020608102448.A1510@cs.pdx.edu \
--to=marius@cs.pdx.edu \
--cc=khalid@ncst.ernet.in \
--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).