From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12990 invoked by alias); 17 Mar 2003 16:44:41 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 12965 invoked from network); 17 Mar 2003 16:44:39 -0000 Received: from unknown (HELO orange.csi.cam.ac.uk) (131.111.8.77) by sources.redhat.com with SMTP; 17 Mar 2003 16:44:39 -0000 Received: from bnd25.robinson.cam.ac.uk ([131.111.236.208]) by orange.csi.cam.ac.uk with esmtp (Exim 4.12) id 18uxj5-0004kA-00; Mon, 17 Mar 2003 16:44:39 +0000 Content-Type: text/plain; charset="iso-8859-1" From: Ben Davis Organization: University of Cambridge To: Jane Liang , "'GCC-help'" Subject: Re: Help wanted Date: Mon, 17 Mar 2003 16:53:00 -0000 User-Agent: KMail/1.4.3 References: <57A168CAC1B2A6409978DF309F6FDB39C4EB12@lgchexch008.ad.lgc.com> In-Reply-To: <57A168CAC1B2A6409978DF309F6FDB39C4EB12@lgchexch008.ad.lgc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200303171654.29698.bnd25@cam.ac.uk> X-SW-Source: 2003-03/txt/msg00196.txt.bz2 On Monday 17 March 2003 4:26 pm, Jane Liang wrote: > Line 8 char *str =3D "0.12000, 0.0, 0.0"; This is a constant string, so it is stored in read-only memory. > Line 13 *ptr =3D '\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[] =3D "0.12000, 0.0, 0.0"; Then the string will be stored temporarily on the stack, which is writable.= =20 The array will be just the right size to accommodate the string. When using GCC, I recommend you compile with -Wwrite-strings. String consta= nts=20 will then be given the 'const' qualifier, and you will get a warning if you= =20 don't use 'const' yourself where necessary: const char *str =3D "0.12000, 0.0, 0.0"; Ben