public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/113793] New: malloc abort on character allocate with source argument
@ 2024-02-06 23:28 manfred99 at gmx dot ch
2024-02-07 19:35 ` [Bug fortran/113793] " anlauf at gcc dot gnu.org
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: manfred99 at gmx dot ch @ 2024-02-06 23:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113793
Bug ID: 113793
Summary: malloc abort on character allocate with source
argument
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: manfred99 at gmx dot ch
Target Milestone: ---
Allocating an allocatable character array, I get a malloc error
when the source argument is not properly padded:
CHARACTER*30,allocatable :: a(:),b(:)
ALLOCATE(a(100),source=" ")
ALLOCATE(b(100),source=" ")
END
yields:
malloc(): corrupted top size
When doing a lame indirection:
CHARACTER*30,allocatable :: a(:),b(:)
CHARACTER*30 :: c=" "
ALLOCATE(a(100),source=c)
ALLOCATE(b(100),source=c)
END
everything is fine.
I don't know whether this is mandated by the standard, but the error
message is not very user friendly and hard to grasp.
I would have expected that the source argument is automatically padded
as with variable assignments and function call arguments.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/113793] malloc abort on character allocate with source argument
2024-02-06 23:28 [Bug fortran/113793] New: malloc abort on character allocate with source argument manfred99 at gmx dot ch
@ 2024-02-07 19:35 ` anlauf at gcc dot gnu.org
2024-02-07 22:09 ` anlauf at gcc dot gnu.org
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-02-07 19:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113793
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |anlauf at gcc dot gnu.org
Ever confirmed|0 |1
Last reconfirmed| |2024-02-07
Keywords| |wrong-code
Status|UNCONFIRMED |NEW
--- Comment #1 from anlauf at gcc dot gnu.org ---
(In reply to Manfred Schwarb from comment #0)
> Allocating an allocatable character array, I get a malloc error
> when the source argument is not properly padded:
>
> CHARACTER*30,allocatable :: a(:),b(:)
> ALLOCATE(a(100),source=" ")
> ALLOCATE(b(100),source=" ")
> END
>
> yields:
> malloc(): corrupted top size
Confirmed.
> I would have expected that the source argument is automatically padded
> as with variable assignments and function call arguments.
The dump-tree shows that it is padded, but the actual malloc is too short:
a.data = (void * restrict) __builtin_malloc (100);
Omitting the source= part, we get the expected:
a.data = (void * restrict) __builtin_malloc (3000);
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/113793] malloc abort on character allocate with source argument
2024-02-06 23:28 [Bug fortran/113793] New: malloc abort on character allocate with source argument manfred99 at gmx dot ch
2024-02-07 19:35 ` [Bug fortran/113793] " anlauf at gcc dot gnu.org
@ 2024-02-07 22:09 ` anlauf at gcc dot gnu.org
2024-04-11 20:29 ` anlauf at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-02-07 22:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113793
--- Comment #2 from anlauf at gcc dot gnu.org ---
Created attachment 57354
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57354&action=edit
Tentative partial patch
This appears to fix the malloc size for character arrays, but not for
allocatable scalars, like in:
program p
implicit none
CHARACTER*30, allocatable :: a(:), b(:,:), d
CHARACTER(kind=4,len=15),allocatable :: c(:), e
ALLOCATE (a(100),source=" ") ! OK
ALLOCATE (b(5,6),source=" ") ! OK
ALLOCATE (c(42), source=4_"zzz") ! OK
ALLOCATE (d,source="xx") ! malloc too small
ALLOCATE (e,source=4_"zz") ! malloc too small
END
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/113793] malloc abort on character allocate with source argument
2024-02-06 23:28 [Bug fortran/113793] New: malloc abort on character allocate with source argument manfred99 at gmx dot ch
2024-02-07 19:35 ` [Bug fortran/113793] " anlauf at gcc dot gnu.org
2024-02-07 22:09 ` anlauf at gcc dot gnu.org
@ 2024-04-11 20:29 ` anlauf at gcc dot gnu.org
2024-04-12 20:28 ` anlauf at gcc dot gnu.org
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-04-11 20:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113793
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #57354|0 |1
is obsolete| |
--- Comment #3 from anlauf at gcc dot gnu.org ---
Created attachment 57931
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57931&action=edit
Improved patch
This patch fixes both the scalar and the array variants.
Needs regtesting.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/113793] malloc abort on character allocate with source argument
2024-02-06 23:28 [Bug fortran/113793] New: malloc abort on character allocate with source argument manfred99 at gmx dot ch
` (2 preceding siblings ...)
2024-04-11 20:29 ` anlauf at gcc dot gnu.org
@ 2024-04-12 20:28 ` anlauf at gcc dot gnu.org
2024-04-12 20:29 ` anlauf at gcc dot gnu.org
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-04-12 20:28 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113793
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #57931|0 |1
is obsolete| |
--- Comment #4 from anlauf at gcc dot gnu.org ---
Created attachment 57938
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57938&action=edit
Enhanced patch
This version add checks for standard conformance and a runtime check for
equal length.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/113793] malloc abort on character allocate with source argument
2024-02-06 23:28 [Bug fortran/113793] New: malloc abort on character allocate with source argument manfred99 at gmx dot ch
` (3 preceding siblings ...)
2024-04-12 20:28 ` anlauf at gcc dot gnu.org
@ 2024-04-12 20:29 ` anlauf at gcc dot gnu.org
2024-04-13 18:04 ` anlauf at gcc dot gnu.org
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-04-12 20:29 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113793
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |accepts-invalid
Priority|P3 |P4
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/113793] malloc abort on character allocate with source argument
2024-02-06 23:28 [Bug fortran/113793] New: malloc abort on character allocate with source argument manfred99 at gmx dot ch
` (4 preceding siblings ...)
2024-04-12 20:29 ` anlauf at gcc dot gnu.org
@ 2024-04-13 18:04 ` anlauf at gcc dot gnu.org
2024-04-16 16:48 ` cvs-commit at gcc dot gnu.org
2024-04-16 18:59 ` anlauf at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-04-13 18:04 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113793
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Assignee|unassigned at gcc dot gnu.org |anlauf at gcc dot gnu.org
Status|NEW |ASSIGNED
--- Comment #5 from anlauf at gcc dot gnu.org ---
Submitted: https://gcc.gnu.org/pipermail/fortran/2024-April/060431.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/113793] malloc abort on character allocate with source argument
2024-02-06 23:28 [Bug fortran/113793] New: malloc abort on character allocate with source argument manfred99 at gmx dot ch
` (5 preceding siblings ...)
2024-04-13 18:04 ` anlauf at gcc dot gnu.org
@ 2024-04-16 16:48 ` cvs-commit at gcc dot gnu.org
2024-04-16 18:59 ` anlauf at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-04-16 16:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113793
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Harald Anlauf <anlauf@gcc.gnu.org>:
https://gcc.gnu.org/g:48024a99e3c2ae522d0026eedd591390506b68ca
commit r14-9996-g48024a99e3c2ae522d0026eedd591390506b68ca
Author: Harald Anlauf <anlauf@gmx.de>
Date: Sat Apr 13 19:09:24 2024 +0200
Fortran: ALLOCATE of fixed-length CHARACTER with SOURCE/MOLD [PR113793]
F2008 requires for ALLOCATE with SOURCE= or MOLD= specifier that the kind
type parameters of allocate-object and source-expr have the same values.
Add compile-time diagnostics for different character length and a runtime
check (under -fcheck=bounds). Use length from allocate-object to prevent
heap corruption and to allow string padding or truncation on assignment.
gcc/fortran/ChangeLog:
PR fortran/113793
* resolve.cc (resolve_allocate_expr): Reject ALLOCATE with SOURCE=
or MOLD= specifier for unequal length.
* trans-stmt.cc (gfc_trans_allocate): If an allocatable character
variable has fixed length, use it and do not use the source length.
With bounds-checking enabled, add a runtime check for same length.
gcc/testsuite/ChangeLog:
PR fortran/113793
* gfortran.dg/allocate_with_source_29.f90: New test.
* gfortran.dg/allocate_with_source_30.f90: New test.
* gfortran.dg/allocate_with_source_31.f90: New test.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug fortran/113793] malloc abort on character allocate with source argument
2024-02-06 23:28 [Bug fortran/113793] New: malloc abort on character allocate with source argument manfred99 at gmx dot ch
` (6 preceding siblings ...)
2024-04-16 16:48 ` cvs-commit at gcc dot gnu.org
@ 2024-04-16 18:59 ` anlauf at gcc dot gnu.org
7 siblings, 0 replies; 9+ messages in thread
From: anlauf at gcc dot gnu.org @ 2024-04-16 18:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113793
anlauf at gcc dot gnu.org changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |14.0
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #7 from anlauf at gcc dot gnu.org ---
Fixed on mainline for gcc-14.
Thanks for the report!
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-04-16 18:59 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-06 23:28 [Bug fortran/113793] New: malloc abort on character allocate with source argument manfred99 at gmx dot ch
2024-02-07 19:35 ` [Bug fortran/113793] " anlauf at gcc dot gnu.org
2024-02-07 22:09 ` anlauf at gcc dot gnu.org
2024-04-11 20:29 ` anlauf at gcc dot gnu.org
2024-04-12 20:28 ` anlauf at gcc dot gnu.org
2024-04-12 20:29 ` anlauf at gcc dot gnu.org
2024-04-13 18:04 ` anlauf at gcc dot gnu.org
2024-04-16 16:48 ` cvs-commit at gcc dot gnu.org
2024-04-16 18:59 ` anlauf at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).