This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, fortran] Simplify constant substrings
- From: Paul Brook <paul at codesourcery dot com>
- To: Steven Bosscher <stevenb at suse dot de>
- Cc: fortran at gcc dot gnu dot org,David Edelsohn <dje at watson dot ibm dot com>,gcc-patches at gcc dot gnu dot org
- Date: Fri, 22 Jul 2005 15:15:28 +0100
- Subject: Re: [PATCH, fortran] Simplify constant substrings
- References: <200507220453.j6M4rCd26890@makai.watson.ibm.com> <200507221608.24498.stevenb@suse.de>
> > ! s = gfc_getmem (end - start + 1);
Should be +2 if you're including the null terminator.
> > ! memcpy (s, p->value.character.string + start, end-start);
> > + p->value.character.string[end - start + 1] = '\0'; /* For debugger
> > */ ! gfc_free (p->value.character.string);
> > ! p->value.character.string = s;
> > ! p->value.character.length = end - start;
>
> However, Paul dislikes the idea of the extra '\0'. I think that if
> we are going to drop it here, then we should drop it everywhere else
> too. But I actually think the extra '\0' is useful because it allows
> you to print value.character.string from gdb.
> Thoughs, anyone?
How about creating gfc_get_string (or some other name it this is already
taked). This is similar to gfc_getmem except it allocates one more byte than
is requested, and zeroes that byte. That way we avoid the ugly explicit null
termination scattered all over the code, and can easily turn it on/off in one
place.
Paul