public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug modula2/109830] New: m2iso library SeqFile.mod - appending to a file overwrites the contents
@ 2023-05-12 14:23 gaius at gcc dot gnu.org
2023-05-12 14:24 ` [Bug modula2/109830] " gaius at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: gaius at gcc dot gnu.org @ 2023-05-12 14:23 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109830
Bug ID: 109830
Summary: m2iso library SeqFile.mod - appending to a file
overwrites the contents
Product: gcc
Version: 14.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: modula2
Assignee: gaius at gcc dot gnu.org
Reporter: gaius at gcc dot gnu.org
Target Milestone: ---
A reported on the gm2 mailing list, attempting to append data to a existing
file using the module SeqFile will overwrite the data. For example:
MODULE seqappend ;
FROM ChanConsts IMPORT OpenResults, old, raw, write, read ;
FROM IOChan IMPORT ChanId, RawWrite, RawRead ;
FROM SYSTEM IMPORT ADR;
FROM libc IMPORT exit, printf ;
FROM StrLib IMPORT StrEqual ;
IMPORT StreamFile;
IMPORT SeqFile;
PROCEDURE stress ;
VAR
cid : ChanId ;
res : OpenResults;
str : ARRAY [0..20] OF CHAR ;
actual: CARDINAL ;
code : INTEGER ;
BEGIN
code := 0 ;
str := '0123456789' ;
(* Open file and create data. *)
StreamFile.Open (cid, 'testdata', write+old+raw, res) ;
IF res = opened
THEN
(* Now write data creating new contents. *)
RawWrite (cid, ADR (str), 10) ;
StreamFile.Close(cid)
ELSE
printf ("failed to open file for write\n") ;
code := 2
END ;
str := 'abcdefghij' ;
(* Now attempt to append the alphabetic str. *)
SeqFile.OpenAppend (cid, 'testdata', write+old+raw, res) ;
IF res = opened
THEN
RawWrite (cid, ADR (str), 10);
SeqFile.Close (cid)
ELSE
printf ("failed to open file for append\n") ;
code := 3
END ;
(* And now test the file for the appended data. *)
StreamFile.Open (cid, 'testdata', read+raw, res) ;
IF res = opened
THEN
(* Now write data creating new contents. *)
RawRead (cid, ADR (str), 20, actual) ;
IF actual # 20
THEN
printf ("short read occurred: %d...\n", actual) ;
code := 5
END ;
StreamFile.Close (cid) ;
str[20] := 0C ;
IF StrEqual (str, '0123456789abcdefghij')
THEN
printf ("append test passed\n")
ELSE
printf ("append test failed\n") ;
code := 1
END
ELSE
printf ("failed to open result file\n") ;
code := 4
END ;
exit (code)
END stress ;
BEGIN
stress
END seqappend.
fails.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug modula2/109830] m2iso library SeqFile.mod - appending to a file overwrites the contents
2023-05-12 14:23 [Bug modula2/109830] New: m2iso library SeqFile.mod - appending to a file overwrites the contents gaius at gcc dot gnu.org
@ 2023-05-12 14:24 ` gaius at gcc dot gnu.org
2023-05-12 14:34 ` gaius at gcc dot gnu.org
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: gaius at gcc dot gnu.org @ 2023-05-12 14:24 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109830
Gaius Mulley <gaius at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Last reconfirmed| |2023-05-12
Status|UNCONFIRMED |ASSIGNED
--- Comment #1 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Confirmed on x86_64 GNU/Linux.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug modula2/109830] m2iso library SeqFile.mod - appending to a file overwrites the contents
2023-05-12 14:23 [Bug modula2/109830] New: m2iso library SeqFile.mod - appending to a file overwrites the contents gaius at gcc dot gnu.org
2023-05-12 14:24 ` [Bug modula2/109830] " gaius at gcc dot gnu.org
@ 2023-05-12 14:34 ` gaius at gcc dot gnu.org
2023-05-12 16:46 ` cvs-commit at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: gaius at gcc dot gnu.org @ 2023-05-12 14:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109830
Gaius Mulley <gaius at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |gaius at gcc dot gnu.org
--- Comment #2 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Created attachment 55065
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55065&action=edit
Proposed fix
Here is a proposed patch which is currently being bootstrap tested.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug modula2/109830] m2iso library SeqFile.mod - appending to a file overwrites the contents
2023-05-12 14:23 [Bug modula2/109830] New: m2iso library SeqFile.mod - appending to a file overwrites the contents gaius at gcc dot gnu.org
2023-05-12 14:24 ` [Bug modula2/109830] " gaius at gcc dot gnu.org
2023-05-12 14:34 ` gaius at gcc dot gnu.org
@ 2023-05-12 16:46 ` cvs-commit at gcc dot gnu.org
2023-05-12 17:09 ` gaius at gcc dot gnu.org
2023-07-28 20:09 ` cvs-commit at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-05-12 16:46 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109830
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Gaius Mulley <gaius@gcc.gnu.org>:
https://gcc.gnu.org/g:1953c0cfb006a696723baa7d5ea14038f6d901a4
commit r14-795-g1953c0cfb006a696723baa7d5ea14038f6d901a4
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date: Fri May 12 17:44:29 2023 +0100
PR modula2/109830 m2iso library SeqFile.mod appending to a file overwrites
content
This patch is for the m2iso library SeqFile.mod to fix a bug when a
file is opened using OpenAppend. The patch checks to see if the file
exists and it uses FIO.OpenForRandom to ensure the file is not
overwritten.
gcc/m2/ChangeLog:
PR modula2/109830
* gm2-libs-iso/SeqFile.mod (newCid): New parameter toAppend
used to select FIO.OpenForRandom.
(OpenRead): Pass extra parameter to newCid.
(OpenWrite): Pass extra parameter to newCid.
(OpenAppend): Pass extra parameter to newCid.
gcc/testsuite/ChangeLog:
PR modula2/109830
* gm2/isolib/run/pass/seqappend.mod: New test.
Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug modula2/109830] m2iso library SeqFile.mod - appending to a file overwrites the contents
2023-05-12 14:23 [Bug modula2/109830] New: m2iso library SeqFile.mod - appending to a file overwrites the contents gaius at gcc dot gnu.org
` (2 preceding siblings ...)
2023-05-12 16:46 ` cvs-commit at gcc dot gnu.org
@ 2023-05-12 17:09 ` gaius at gcc dot gnu.org
2023-07-28 20:09 ` cvs-commit at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: gaius at gcc dot gnu.org @ 2023-05-12 17:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109830
Gaius Mulley <gaius at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |FIXED
Status|ASSIGNED |RESOLVED
--- Comment #4 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Closing now that the patch has been applied.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug modula2/109830] m2iso library SeqFile.mod - appending to a file overwrites the contents
2023-05-12 14:23 [Bug modula2/109830] New: m2iso library SeqFile.mod - appending to a file overwrites the contents gaius at gcc dot gnu.org
` (3 preceding siblings ...)
2023-05-12 17:09 ` gaius at gcc dot gnu.org
@ 2023-07-28 20:09 ` cvs-commit at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-28 20:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109830
--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Gaius Mulley
<gaius@gcc.gnu.org>:
https://gcc.gnu.org/g:55156f50e7c14d63f6c31a65cfdf61c1de33359d
commit r13-7634-g55156f50e7c14d63f6c31a65cfdf61c1de33359d
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date: Fri Jul 28 21:08:29 2023 +0100
PR modula2/109830 m2iso library SeqFile.mod appending to a file overwrites
content
This patch is for the m2iso library SeqFile.mod to fix a bug when a
file is opened using OpenAppend. The patch checks to see if the file
exists and it uses FIO.OpenForRandom to ensure the file is not
overwritten.
gcc/m2/ChangeLog:
PR modula2/109830
* gm2-libs-iso/SeqFile.mod (newCid): New parameter toAppend
used to select FIO.OpenForRandom.
(OpenRead): Pass extra parameter to newCid.
(OpenWrite): Pass extra parameter to newCid.
(OpenAppend): Pass extra parameter to newCid.
gcc/testsuite/ChangeLog:
PR modula2/109830
* gm2/isolib/run/pass/seqappend.mod: New test.
(cherry picked from commit 1953c0cfb006a696723baa7d5ea14038f6d901a4)
Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2023-07-28 20:09 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-12 14:23 [Bug modula2/109830] New: m2iso library SeqFile.mod - appending to a file overwrites the contents gaius at gcc dot gnu.org
2023-05-12 14:24 ` [Bug modula2/109830] " gaius at gcc dot gnu.org
2023-05-12 14:34 ` gaius at gcc dot gnu.org
2023-05-12 16:46 ` cvs-commit at gcc dot gnu.org
2023-05-12 17:09 ` gaius at gcc dot gnu.org
2023-07-28 20:09 ` cvs-commit 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).