From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17355 invoked by alias); 17 Mar 2003 16:53:18 -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 17266 invoked from network); 17 Mar 2003 16:53:17 -0000 Received: from unknown (HELO junior.lgc.com) (134.132.72.99) by sources.redhat.com with SMTP; 17 Mar 2003 16:53:17 -0000 Received: from lgchvw01.lgc.com (lgchvw01.lgc.com [134.132.93.107]) by junior.lgc.com (8.11.6/8.11.3) with SMTP id h2HGpej10627; Mon, 17 Mar 2003 10:51:40 -0600 (CST) Received: from 134.132.93.152 by lgchvw01.lgc.com (InterScan E-Mail VirusWall NT); Mon, 17 Mar 2003 10:52:34 -0600 Received: by lgchexchbh.ad.lgc.com with Internet Mail Service (5.5.2653.19) id <1C7PQNAM>; Mon, 17 Mar 2003 10:52:34 -0600 Message-ID: <57A168CAC1B2A6409978DF309F6FDB39C4EB16@lgchexch008.ad.lgc.com> From: Jane Liang To: "'Ben Davis'" , Jane Liang , "'GCC-help'" Subject: RE: Help wanted Date: Mon, 17 Mar 2003 19:16:00 -0000 MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2003-03/txt/msg00197.txt.bz2 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