diff options
author | Tobias Schlüter <tobi@gcc.gnu.org> | 2007-09-02 17:04:11 +0200 |
---|---|---|
committer | Tobias Schlüter <tobi@gcc.gnu.org> | 2007-09-02 17:04:11 +0200 |
commit | b35c5f019f9dcbee023c54f25be644d90a5a76ac (patch) | |
tree | b1033e746be3cb7c89de5e10ac9e96f485193407 /gcc/fortran/expr.c | |
parent | 3c83544d6217312fff8dd1808e626e3c6188d449 (diff) | |
download | gcc-b35c5f019f9dcbee023c54f25be644d90a5a76ac.zip gcc-b35c5f019f9dcbee023c54f25be644d90a5a76ac.tar.gz gcc-b35c5f019f9dcbee023c54f25be644d90a5a76ac.tar.bz2 |
dump-parse-tree.c (show_char_const): New function.
fortran/
* dump-parse-tree.c (show_char_const): New function.
(gfc_show_expr): Use it.
* expr.c (find_substring_ref): Rework to not keep characters
dangling beyond end of string.
testsuite/
* gfortran.dg/substr_6.f90: New test.
From-SVN: r128027
Diffstat (limited to 'gcc/fortran/expr.c')
-rw-r--r-- | gcc/fortran/expr.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 8c44028..ebed1f2 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -1329,6 +1329,7 @@ find_substring_ref (gfc_expr *p, gfc_expr **newp) { int end; int start; + int length; char *chr; if (p->ref->u.ss.start->expr_type != EXPR_CONSTANT @@ -1336,13 +1337,16 @@ find_substring_ref (gfc_expr *p, gfc_expr **newp) return FAILURE; *newp = gfc_copy_expr (p); - chr = p->value.character.string; + gfc_free ((*newp)->value.character.string); + end = (int) mpz_get_ui (p->ref->u.ss.end->value.integer); start = (int) mpz_get_ui (p->ref->u.ss.start->value.integer); + length = end - start + 1; - (*newp)->value.character.length = end - start + 1; - strncpy ((*newp)->value.character.string, &chr[start - 1], - (*newp)->value.character.length); + chr = (*newp)->value.character.string = gfc_getmem (length + 1); + (*newp)->value.character.length = length; + memcpy (chr, &p->value.character.string[start - 1], length); + chr[length] = '\0'; return SUCCESS; } |