------- Comment #17 from fxcoudert at gcc dot gnu dot org 2006-10-30 16:46 ------- The following patch fixes the problem:
Index: data.c =================================================================== --- data.c (revision 118134) +++ data.c (working copy) @@ -155,7 +155,8 @@ init->expr_type = EXPR_CONSTANT; init->ts = *ts; - dest = gfc_getmem (len); + dest = gfc_getmem (len + 1); + dest[len] = '\0'; init->value.character.length = len; init->value.character.string = dest; /* Blank the string if we're only setting a substring. */ Index: decl.c =================================================================== --- decl.c (revision 118134) +++ decl.c (working copy) @@ -753,10 +753,11 @@ slen = expr->value.character.length; if (len != slen) { - s = gfc_getmem (len); + s = gfc_getmem (len + 1); memcpy (s, expr->value.character.string, MIN (len, slen)); if (len > slen) memset (&s[slen], ' ', len - slen); + s[len] = '\0'; gfc_free (expr->value.character.string); expr->value.character.string = s; expr->value.character.length = len; Index: expr.c =================================================================== --- expr.c (revision 118134) +++ expr.c (working copy) @@ -1438,7 +1438,7 @@ gfc_extract_int (p->ref->u.ss.end, &end); s = gfc_getmem (end - start + 1); memcpy (s, p->value.character.string + start, end - start); - s[end] = '\0'; /* TODO: C-style string for debugging. */ + s[end-start+1] = '\0'; /* TODO: C-style string for debugging. */ gfc_free (p->value.character.string); p->value.character.string = s; p->value.character.length = end - start; Before submitting it, I'd like to audit the rest of the front-end code for problems similar to those in decl.c and data.c. -- fxcoudert at gcc dot gnu dot org changed: What |Removed |Added ---------------------------------------------------------------------------- AssignedTo|unassigned at gcc dot gnu |fxcoudert at gcc dot gnu dot |dot org |org Status|NEW |ASSIGNED Keywords| |patch Last reconfirmed|2006-10-17 13:01:41 |2006-10-30 16:46:22 date| | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29067