]> git.ipfire.org Git - thirdparty/gcc.git/commit
Fortran: Fix issue with using snprintf function.
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Thu, 7 Mar 2024 03:46:04 +0000 (19:46 -0800)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Thu, 7 Mar 2024 03:57:05 +0000 (19:57 -0800)
commit03932d3203bce244edd812b81921c2f16ea18d86
tree569f6843f3695eabfd0a7f23ea0679b1bbdc66a5
parent8b483cd5521de79c13cf4807fd004d442b9ad9cd
Fortran: Fix issue with using snprintf function.

The previous patch used snprintf to set the message
string. The message string is not a formatted string
and the snprintf will interpret '%' related characters
as format specifiers when there are no associated
output variables. A segfault ensues.

This change replaces snprintf with a fortran string copy
function and null terminates the message string.

PR libfortran/105456

libgfortran/ChangeLog:

* io/list_read.c (list_formatted_read_scalar): Use fstrcpy
from libgfortran/runtime/string.c to replace snprintf.
(nml_read_obj): Likewise.
* io/transfer.c (unformatted_read): Likewise.
(unformatted_write): Likewise.
(formatted_transfer_scalar_read): Likewise.
(formatted_transfer_scalar_write): Likewise.
* io/write.c (list_formatted_write_scalar): Likewise.
(nml_write_obj): Likewise.

gcc/testsuite/ChangeLog:

* gfortran.dg/pr105456.f90: Revise using '%' characters
in users error message.
gcc/testsuite/gfortran.dg/pr105456.f90
libgfortran/io/list_read.c
libgfortran/io/transfer.c
libgfortran/io/write.c