This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH, fortran] Simplify constant substrings


> > ! 	  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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]