diff options
author | Jerry DeLisle <jvdelisle@gcc.gnu.org> | 2024-03-06 19:46:04 -0800 |
---|---|---|
committer | Jerry DeLisle <jvdelisle@gcc.gnu.org> | 2024-03-06 19:57:05 -0800 |
commit | 03932d3203bce244edd812b81921c2f16ea18d86 (patch) | |
tree | 569f6843f3695eabfd0a7f23ea0679b1bbdc66a5 /gcc | |
parent | 8b483cd5521de79c13cf4807fd004d442b9ad9cd (diff) | |
download | gcc-03932d3203bce244edd812b81921c2f16ea18d86.zip gcc-03932d3203bce244edd812b81921c2f16ea18d86.tar.gz gcc-03932d3203bce244edd812b81921c2f16ea18d86.tar.bz2 |
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/gfortran.dg/pr105456.f90 | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/gcc/testsuite/gfortran.dg/pr105456.f90 b/gcc/testsuite/gfortran.dg/pr105456.f90 index 1883238..60cd3b6 100644 --- a/gcc/testsuite/gfortran.dg/pr105456.f90 +++ b/gcc/testsuite/gfortran.dg/pr105456.f90 @@ -19,7 +19,7 @@ contains character :: ch read (unit,fmt='(A1)', advance="no", iostat=piostat, iomsg=piomsg) ch piostat = 42 - piomsg="The users message" + piomsg="The users message containing % and %% and %s and other stuff" dtv%ch = ch end subroutine read_formatted end module sk1 @@ -35,4 +35,4 @@ program skip1 write (*,'(10(A))') "Read: '",x%ch,"'" end program skip1 ! { dg-output ".*(unit = 10, file = .*)" } -! { dg-output "Fortran runtime error: The users message" } +! { dg-output "Fortran runtime error: The users message containing % and %% and %s and other stuff" } |