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

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).