diff options
Diffstat (limited to 'gcc/fortran/expr.c')
-rw-r--r-- | gcc/fortran/expr.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index d3f0ddf5cce..0ca7dbfcae2 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -449,19 +449,32 @@ gfc_copy_expr (gfc_expr *p) s = gfc_getmem (p->value.character.length + 1); q->value.character.string = s; - memcpy (s, p->value.character.string, p->value.character.length + 1); + /* This is the case for the C_NULL_CHAR named constant. */ + if (p->value.character.length == 0 + && (p->ts.is_c_interop || p->ts.is_iso_c)) + { + *s = '\0'; + /* Need to set the length to 1 to make sure the NUL + terminator is copied. */ + q->value.character.length = 1; + } + else + memcpy (s, p->value.character.string, + p->value.character.length + 1); } break; case BT_HOLLERITH: case BT_LOGICAL: case BT_DERIVED: - break; /* Already done */ + break; /* Already done. */ case BT_PROCEDURE: + case BT_VOID: + /* Should never be reached. */ case BT_UNKNOWN: gfc_internal_error ("gfc_copy_expr(): Bad expr node"); - /* Not reached */ + /* Not reached. */ } break; |