public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/67669] New: Wrong works fwrite or fread or both
@ 2015-09-21 13:25 beyzman at gmail dot com
  2015-09-21 13:28 ` [Bug c++/67669] " beyzman at gmail dot com
  2015-09-21 13:32 ` beyzman at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: beyzman at gmail dot com @ 2015-09-21 13:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67669

            Bug ID: 67669
           Summary: Wrong works fwrite or fread or both
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: beyzman at gmail dot com
  Target Milestone: ---

Created attachment 36365
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36365&action=edit
Example of file to be processed

The program below is intended to replace every symbol with code \x00 by symbol
\x20 in some file.
The program was compiled by g++ for Windows from MinGW packet.
In the example attached there is symbols with code \x00 after every symbols
'j'.
It is intended that after program is executed, there will be symbols with code
\x20 after every symbol 'j'. But it is not so.
If I decomment 2 lines commented, the programm works as intended.



//#include <QTCore>
#include <stdio.h>
#pragma hdrstop
#define min(a, b)  (((a) < (b)) ? (a) : (b))

int main(int argc, char *argv[])
{
   FILE *f;
   int pos;
   const int bufSize = 10;
   int length;
   int piece;
   int i;
   int ret;
   int chSw = 0;
   const char *fileName = argv[1];
   char *buf;
   if (argc < 1) printf("USAGE:  02space.exe <filename>\nReplaces every symbol
\\0x00 by space\n");
   f = fopen(fileName,"rb+");
   if (!f)
   {
       printf("Can not open file %s",argv[1]);
       return -1;
   }
   fseek(f,0,SEEK_END);
   length = ftell(f);
   rewind (f);
   ret = 0;
   buf = new char[bufSize];
   for(piece = (int)(min(bufSize,length)); length > 0;
         length -= piece,piece = (int)(min(bufSize,length)))
   {
     ++ret;
     pos = ftell(f)  ;
     fread(buf,piece,1,f);
     chSw = 0;
     for (i = 0; i < piece; ++i)
     {
         if (buf[i] == '\x00')
         {
             buf[i] = ' ';
             chSw = 1;
         }
     }

     if (chSw)
     {

       fseek(f,pos,SEEK_SET);
       fwrite(buf,piece,1,f);
//       fseek(f,pos,SEEK_SET);
//       fread(buf, piece, 1,f);
     }
   }

   delete [] buf;
   fclose(f);
   return 0;
}


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/67669] Wrong works fwrite or fread or both
  2015-09-21 13:25 [Bug c++/67669] New: Wrong works fwrite or fread or both beyzman at gmail dot com
@ 2015-09-21 13:28 ` beyzman at gmail dot com
  2015-09-21 13:32 ` beyzman at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: beyzman at gmail dot com @ 2015-09-21 13:28 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67669

--- Comment #1 from Bernard <beyzman at gmail dot com> ---
Created attachment 36366
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36366&action=edit
Source


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c++/67669] Wrong works fwrite or fread or both
  2015-09-21 13:25 [Bug c++/67669] New: Wrong works fwrite or fread or both beyzman at gmail dot com
  2015-09-21 13:28 ` [Bug c++/67669] " beyzman at gmail dot com
@ 2015-09-21 13:32 ` beyzman at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: beyzman at gmail dot com @ 2015-09-21 13:32 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67669

--- Comment #2 from Bernard <beyzman at gmail dot com> ---
The same source compiled for UBUNTU works well.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-09-21 13:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-21 13:25 [Bug c++/67669] New: Wrong works fwrite or fread or both beyzman at gmail dot com
2015-09-21 13:28 ` [Bug c++/67669] " beyzman at gmail dot com
2015-09-21 13:32 ` beyzman at gmail dot com

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