[Bug libfortran/125087] libgfortran/io/format.c:285: Pointless assignment ?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125087 anlauf at gcc dot gnu.org changed: What|Removed |Added Target Milestone|--- |17.0 Resolution|--- |FIXED Status|ASSIGNED|RESOLVED --- Comment #9 from anlauf at gcc dot gnu.org --- Should be fixed now. Closing. Thanks for the report!
[Bug libfortran/125087] libgfortran/io/format.c:285: Pointless assignment ?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125087 --- Comment #8 from GCC Commits --- The master branch has been updated by Harald Anlauf : https://gcc.gnu.org/g:05c76637481870f2c3b3c970f0a16adad1652143 commit r17-414-g05c76637481870f2c3b3c970f0a16adad1652143 Author: Harald Anlauf Date: Fri May 8 21:45:31 2026 +0200 libfortran: fix static analyser cppcheck warning in free_format_data [PR125087] The static analyser cppcheck reported a pointless assignment in function free_format_data. The intent of the assignment was to finally nullify the pointer to allocated format data after memory has been freed. Since C does not support references, add a level of indirection to the function argument so that the dereferenced argument can be nullified. PR libfortran/125087 libgfortran/ChangeLog: * io/format.c (free_format_data): Change argument from pointer to format_data to pointer to pointer of object. (free_format_hash_table): Adjust argument passed to free_format_data. (save_parsed_format): Likewise. * io/format.h (free_format_data): Adjust prototype. * io/transfer.c (st_read_done_worker): Adjust argument passed to free_format_data. (st_write_done_worker): Likewise.
[Bug libfortran/125087] libgfortran/io/format.c:285: Pointless assignment ?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125087 anlauf at gcc dot gnu.org changed: What|Removed |Added Ever confirmed|0 |1 Status|UNCONFIRMED |ASSIGNED Last reconfirmed||2026-05-08 Assignee|unassigned at gcc dot gnu.org |anlauf at gcc dot gnu.org --- Comment #7 from anlauf at gcc dot gnu.org --- (In reply to David Binderman from comment #6) > (In reply to Jerry DeLisle from comment #5) > > Applies and tests OK. If it passes the static analyser cppcheck its OK by > > me. > > Original cppcheck warning gone after applying the patch. > Looks good to me. Jerry, David, thanks for confirming! I'll wrap up and push to mainline later tonight.
[Bug libfortran/125087] libgfortran/io/format.c:285: Pointless assignment ?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125087 --- Comment #6 from David Binderman --- (In reply to Jerry DeLisle from comment #5) > Applies and tests OK. If it passes the static analyser cppcheck its OK by me. Original cppcheck warning gone after applying the patch. Looks good to me.
[Bug libfortran/125087] libgfortran/io/format.c:285: Pointless assignment ?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125087 --- Comment #5 from Jerry DeLisle --- (In reply to anlauf from comment #4) > Created attachment 64378 [details] > Draft patch > > Potential plain C solution. (Pass-by-reference in C++ would be simpler...) Applies and tests OK. If it passes the static analyser cppcheck its OK by me.
[Bug libfortran/125087] libgfortran/io/format.c:285: Pointless assignment ?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125087 --- Comment #4 from anlauf at gcc dot gnu.org --- Created attachment 64378 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=64378&action=edit Draft patch Potential plain C solution. (Pass-by-reference in C++ would be simpler...)
[Bug libfortran/125087] libgfortran/io/format.c:285: Pointless assignment ?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125087
anlauf at gcc dot gnu.org changed:
What|Removed |Added
CC||anlauf at gcc dot gnu.org
--- Comment #3 from anlauf at gcc dot gnu.org ---
(In reply to Jerry DeLisle from comment #2)
> (In reply to anlauf from comment #1)
> > Some context:
> >
> > /* free_format_data()-- Free all allocated format data. */
> >
> > void
> > free_format_data (format_data *fmt)
> > {
> > ...
> > free (fmt);
> > fmt = NULL;
> > }
> >
> > It looks like the intent was to nullify the pointer in the caller,
> > but this does not work the way it is coded.
>
> The intent was to set it to NULL so that if the function is called again it
> will do nothing.
>
> void
> free_format_data (format_data *fmt)
> {
> fnode_array *fa, *fa_next;
> fnode *fnp;
>
> if (fmt == NULL)
> return;
> ...
>
> to avoid attempting to free the format hash table if it has already been
> freed.
Since we are stuck with C in libgfortran, a possible solution is:
void
free_format_data (format_data **fmt)
and adaptation of the remaining code.
What do you think?
[Bug libfortran/125087] libgfortran/io/format.c:285: Pointless assignment ?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125087
Jerry DeLisle changed:
What|Removed |Added
CC||jvdelisle at gcc dot gnu.org
--- Comment #2 from Jerry DeLisle ---
(In reply to anlauf from comment #1)
> Some context:
>
> /* free_format_data()-- Free all allocated format data. */
>
> void
> free_format_data (format_data *fmt)
> {
> ...
> free (fmt);
> fmt = NULL;
> }
>
> It looks like the intent was to nullify the pointer in the caller,
> but this does not work the way it is coded.
The intent was to set it to NULL so that if the function is called again it
will do nothing.
void
free_format_data (format_data *fmt)
{
fnode_array *fa, *fa_next;
fnode *fnp;
if (fmt == NULL)
return;
...
to avoid attempting to free the format hash table if it has already been freed.
[Bug libfortran/125087] libgfortran/io/format.c:285: Pointless assignment ?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125087
--- Comment #1 from anlauf at gcc dot gnu.org ---
Some context:
/* free_format_data()-- Free all allocated format data. */
void
free_format_data (format_data *fmt)
{
...
free (fmt);
fmt = NULL;
}
It looks like the intent was to nullify the pointer in the caller,
but this does not work the way it is coded.
