[Bug c++/67669] Wrong works fwrite or fread or both

2015-12-16 Thread beyzman at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67669

--- Comment #4 from Bernard  ---
(In reply to Martin Sebor from comment #3)
> I don't have access to a Windows machine and I can't confirm this on Linux,
> but 
> I doubt the problem is due to GCC and suspect it's more likely due to some
> bug/oddity in Windows and its newline handling (I did notice the "b" in the
> call to fopen which should avoid these problems but still).

Hi, I doubt that problem in Windows, because the same source compiled by
Borland C++ Builder works well.

[Bug c++/67669] Wrong works fwrite or fread or both

2015-09-21 Thread beyzman at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67669

--- Comment #2 from Bernard  ---
The same source compiled for UBUNTU works well.


[Bug c++/67669] New: Wrong works fwrite or fread or both

2015-09-21 Thread beyzman at gmail dot com
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=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 
#include 
#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 \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;
}


[Bug c++/67669] Wrong works fwrite or fread or both

2015-09-21 Thread beyzman at gmail dot com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67669

--- Comment #1 from Bernard  ---
Created attachment 36366
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36366=edit
Source