public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jane Liang <JLiang@lgc.com>
To: "'Ben Davis'" <bnd25@cam.ac.uk>, Jane Liang <JLiang@lgc.com>,
	"'GCC-help'" <gcc-help@gcc.gnu.org>
Subject: RE: Help wanted
Date: Mon, 17 Mar 2003 19:16:00 -0000	[thread overview]
Message-ID: <57A168CAC1B2A6409978DF309F6FDB39C4EB16@lgchexch008.ad.lgc.com> (raw)

Hi, Ben:

It works!

Thanks!
 
Jane


-----Original Message-----
From: Ben Davis [mailto:bnd25@cam.ac.uk] 
Sent: Monday, March 17, 2003 10:54 AM
To: Jane Liang; 'GCC-help'
Subject: Re: Help wanted


On Monday 17 March 2003 4:26 pm, Jane Liang wrote:
> Line 8      char *str = "0.12000, 0.0, 0.0";

This is a constant string, so it is stored in read-only memory.

> Line 13     *ptr = '\0';

You are now writing to read-only memory. Hence the crash.

You can fix your code by making 'str' an array instead:

   char str[] = "0.12000, 0.0, 0.0";

Then the string will be stored temporarily on the stack, which is writable. 
The array will be just the right size to accommodate the string.

When using GCC, I recommend you compile with -Wwrite-strings. String
constants 
will then be given the 'const' qualifier, and you will get a warning if you 
don't use 'const' yourself where necessary:

   const char *str = "0.12000, 0.0, 0.0";

Ben

             reply	other threads:[~2003-03-17 16:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-17 19:16 Jane Liang [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-03-17 16:44 Jane Liang
2003-03-17 16:53 ` Ben Davis
2002-08-12  8:22 help wanted rojesh  p
2001-10-10 22:06 Danish Samad
2001-10-10 23:44 ` Rupert Wood

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=57A168CAC1B2A6409978DF309F6FDB39C4EB16@lgchexch008.ad.lgc.com \
    --to=jliang@lgc.com \
    --cc=bnd25@cam.ac.uk \
    --cc=gcc-help@gcc.gnu.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 read-only IMAP folder(s) and NNTP newsgroup(s).