Fix an undefined behavior in fortran/decl.c
authorQing Zhao <qing.zhao@oracle.com>
Fri, 1 Dec 2017 18:20:45 +0000 (18:20 +0000)
committerQing Zhao <qinzhao@gcc.gnu.org>
Fri, 1 Dec 2017 18:20:45 +0000 (18:20 +0000)
From-SVN: r255332

gcc/fortran/ChangeLog
gcc/fortran/decl.c

index b7f8a5856e421d99cdd70e3697b26d28586ce451..e5865dc892dcb5b0d0ffe7759263b11b19869367 100644 (file)
@@ -1,3 +1,8 @@
+2017-12-01  Qing Zhao  <qing.zhao@oracle.com>
+
+       * decl.c (gfc_get_pdt_instance): Adjust the call to sprintf
+       to avoid the same buffer being both source and destination.
+
 2017-12-01  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/83224
index 67e1c5bf314aa278280ff8b89c5951dcc547ddb4..d46083c0a93b859590e05698d5908a5da1a50b2c 100644 (file)
@@ -3362,7 +3362,7 @@ gfc_get_pdt_instance (gfc_actual_arglist *param_list, gfc_symbol **sym,
        }
 
       gfc_extract_int (kind_expr, &kind_value);
-      sprintf (name, "%s_%d", name, kind_value);
+      sprintf (name + strlen (name), "_%d", kind_value);
 
       if (!name_seen && actual_param)
        actual_param = actual_param->next;