Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/CodeGuard    [ Add a report in this area ]  
Report #:  46102   Status: Open
CodeGuard give incorrect message for fgetc function
Project:  C++Builder Build #:  2006 - XE
Version:    15.1 Submitted By:   Sergiy Kanilo
Report Type:  Basic functionality failure Date Reported:  5/16/2007 6:45:35 PM
Severity:    Commonly encountered problem Last Updated: 3/20/2012 2:24:39 AM
Platform:    All versions Internal Tracking #:   255798
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: (5 Total Ratings)
4.80 out of 5
Total Votes: 88
Description
#include <fstream>
#include <string>
int main()
{
std::ifstream file( "test.txt" );
std::string line;
std::getline( file, line );
return 0;
}

causes

Bad parameter in process: Project1.exe(2224)  - c:\program
files\borland\bds\4.0\include\dinkumware\fstream#23
  A bad file or pipe stream (0x3279C0F8) has been passed to the function.
  0x00409A98 Call to fgetc(0x3279C0F8)
    0x004095C2 - c:\program
files\borland\bds\4.0\include\dinkumware\fstream#23
    0x0040846D - c:\program
files\borland\bds\4.0\include\dinkumware\fstream#366
    0x004037FA - c:\program
files\borland\bds\4.0\include\dinkumware\streambuf#97
    0x00403662 - c:\program
files\borland\bds\4.0\include\dinkumware\streambuf#114
    0x00402426 - c:\program
files\borland\bds\4.0\include\dinkumware\string#574
    0x0040170D - c:\program
files\borland\bds\4.0\include\dinkumware\string#612

if you compile using BDS2006 with "All Codeguard options on'

Strange enough, but there are no codeguard messages if file does not exist.
Steps to Reproduce:
Use Console project,
in options set
"All codeguard options on"

unit1.cpp should be

#include <fstream>
#include <string>
int main()
{
std::ifstream file( "test.txt" );
std::string line;
std::getline( file, line );
return 0;
}

Create test.txt and type something in it
(in directory where program executes)

Press F9 (Run)
Workarounds
Turn off Dynamic RTL
Attachment
JED78.zip
Comments

Fabrizio Benedetti at 7/30/2008 1:11:10 AM -
I also find this condition when writing to a file using an ofstream (which in the end resolves to fputc, which seems to suffer from the same CG problem than fgetc).

Fabrizio Benedetti at 7/30/2008 1:18:18 AM -
Moreover, after the CG message has appeared some 20 times, the IDE starts trapping this exceptions at each subsequent CG message:

[200315F3]{rtl100.bpl  } Classes.TList.Add (Line 2918, "common\Classes.pas" + 1) + $0
[2004A1C8]{rtl100.bpl  } Contnrs.TObjectList.Add (Line 251, "common\Contnrs.pas" + 0) + $0
[20A16933]{coreide100.bpl} MsgLinesIntf.TLine.AddChild (Line 130, "MsgLinesIntf.pas" + 2) + $5
[20A307CE]{coreide100.bpl} IDEServices.AddAllMessages (Line 2396, "IDEServices.pas" + 6) + $5
[20A308B0]{coreide100.bpl} IDEServices.TIDEServices.AddCustomMessage (Line 2410, "IDEServices.pas" + 6) + $6
[20A30937]{coreide100.bpl} IDEServices.TIDEServices.AddCustomMessage (Line 2423, "IDEServices.pas" + 0) + $3
[059138F7]{codeguardide100.bpl} CodeGuardAddIn.TProductStartup.CGEventOccurred (Line 520, "CodeGuardAddIn.pas" + 125) + $F
[21B32B5B]{win32debugide100.bpl} Win32Debug.TDbkCGEvBreakpoint.whenOccurs (Line 296, "Win32Debug.pas" + 17) + $3F
[200E7B4E]{vcl100.bpl  } Graphics.TCanvas.Unlock (Line 2712, "Graphics.pas" + 4) + $5
[200EBC2E]{vcl100.bpl  } Graphics.TBitmapCanvas.FreeContext (Line 5112, "Graphics.pas" + 12) + $3
[200E7B4E]{vcl100.bpl  } Graphics.TCanvas.Unlock (Line 2712, "Graphics.pas" + 4) + $5
[200EBA80]{vcl100.bpl  } Graphics.FreeMemoryContexts (Line 5057, "Graphics.pas" + 9) + $3
[20142498]{vcl100.bpl  } Controls.TWinControl.WMNCHitTest (Line 8304, "Controls.pas" + 5) + $4
[20E746E1]{vclide100.bpl} IDEVirtualTrees.TBaseVirtualTree.WMNCHitTest (Line 16327, "idevirtualtrees.pas" + 1) + $4
[20006A3F]{rtl100.bpl  } System.TObject.Dispatch (Line 9284, "sys\system.pas" + 8) + $0
[2003FC55]{rtl100.bpl  } Classes.TComponent.UpdateAction (Line 10761, "common\Classes.pas" + 1) + $6
[2015EA96]{vcl100.bpl  } Forms.ProcessUpdate (Line 5955, "Forms.pas" + 1) + $13
[20006936]{rtl100.bpl  } System.@IsClass (Line 9077, "sys\system.pas" + 1) + $8
[2003FC55]{rtl100.bpl  } Classes.TComponent.UpdateAction (Line 10761, "common\Classes.pas" + 1) + $6
[2015EA96]{vcl100.bpl  } Forms.ProcessUpdate (Line 5955, "Forms.pas" + 1) + $13
[20006936]{rtl100.bpl  } System.@IsClass (Line 9077, "sys\system.pas" + 1) + $8
[2003FC55]{rtl100.bpl  } Classes.TComponent.UpdateAction (Line 10761, "common\Classes.pas" + 1) + $6
[2015EA96]{vcl100.bpl  } Forms.ProcessUpdate (Line 5955, "Forms.pas" + 1) + $13
[20006936]{rtl100.bpl  } System.@IsClass (Line 9077, "sys\system.pas" + 1) + $8
[2015EB0D]{vcl100.bpl  } Forms.TraverseClients (Line 5968, "Forms.pas" + 5) + $2D
[2003FC55]{rtl100.bpl  } Classes.TComponent.UpdateAction (Line 10761, "common\Classes.pas" + 1) + $6
[2013C527]{vcl100.bpl  } Controls.TControl.WndProc (Line 5146, "Controls.pas" + 83) + $6
[201406A7]{vcl100.bpl  } Controls.TWinControl.WndProc (Line 7304, "Controls.pas" + 111) + $6
[20159E7F]{vcl100.bpl  } Forms.TCustomForm.WndProc (Line 3512, "Forms.pas" + 136) + $5
[20040E4C]{rtl100.bpl  } Classes.StdWndProc (Line 11583, "common\Classes.pas" + 8) + $0
[20885499]{dbkdebugide100.bpl} Debug.TDebugger.DBKWndProc (Line 11455, "Debug.pas" + 3) + $1F
[20040E4C]{rtl100.bpl  } Classes.StdWndProc (Line 11583, "common\Classes.pas" + 8) + $0
[201625F0]{vcl100.bpl  } Forms.TApplication.ProcessMessage (Line 8105, "Forms.pas" + 23) + $1
[2016262A]{vcl100.bpl  } Forms.TApplication.HandleMessage (Line 8124, "Forms.pas" + 1) + $4
[2016291F]{vcl100.bpl  } Forms.TApplication.Run (Line 8223, "Forms.pas" + 20) + $3
[0042297A]{bds.exe     } bds.bds (Line 195, "" + 7) + $7

Fabrizio Benedetti at 7/30/2008 1:20:40 AM -
I counted the # of lines appearing in the CG log before the IDE starts trapping exceptions, it's 64.

Fabrizio Benedetti at 7/30/2008 1:22:39 AM -
Moreover, disabling CG tracking for fputc() from "Tools | CodeGuard configuration | Function options" is not working, CG goes on logging.

Kirill Andreev at 9/12/2008 12:33:22 AM -
the code Reproduce too:

    FILE *f=fopen("config.xml","r");
    fseek(f,0,SEEK_END);

Company Licence1 at 12/21/2009 4:50:04 AM -
I'm using RAD Studio 2010 with Windows 7. I get the also this error-message with codeguard.
Is there no solution?
The workaround (no dyn. rtl) delieveres the same error.

Are there an alternative way to use fstream?

My program:

AnsiString filename = "C:\\debug.txt";
sout.open(filename.c_str(), ios::trunc);
cout.rdbuf(sout.rdbuf());
cout << "Test";
cout.flush();

21.12.2009 13:44:04 CodeGuard(tm)-Prozess wurde gestartet: Project1.exe(916)
Falscher Parameter im Prozess: Project1.exe(916)  - c:\program files\embarcadero\rad studio\7.0\include\dinkumware\fstream#55
  Falsches Datei- oder Pipe-Stream (0x32AFD894) wurde an die Funktion weitergegeben.
  0x00406AA0 Aufruf von fputc(0x54 ['T'], 0x32AFD894)
    0x00405974 - c:\program files\embarcadero\rad studio\7.0\include\dinkumware\fstream#55
    0x0040499C - c:\program files\embarcadero\rad studio\7.0\include\dinkumware\fstream#246
    0x004047C4 - c:\program files\embarcadero\rad studio\7.0\include\dinkumware\streambuf#465
    0x004022A2 - c:\program files\embarcadero\rad studio\7.0\include\dinkumware\streambuf#151
    0x00401C76 - c:\program files\embarcadero\rad studio\7.0\include\dinkumware\ostream#683
    0x004018AE - C:\Users\Meins\Documents\RAD Studio\Projekte\Project1.cpp#27

Christian Gudrian at 3/4/2010 6:03:16 AM -
I've encountered a possibly related issue:

#include <sstream>
int main() {
   std::ostringstream s;
   s << 42;
   return 0;
}

CodeGuard says:

Pointer arithmetic underrun in process: Project1.exe(5796)  - c:\program files (x86)\embarcadero\rad studio\7.0\include\../include/dinkumware/streambuf#201
  0x00000000-0x02035458, that is at offset 0-33772632 in block 0x02035458 (size 32).
    0x00403DE0 - c:\program files (x86)\embarcadero\rad studio\7.0\include\../include/dinkumware/streambuf#201
    0x00407DE6 - c:\program files (x86)\embarcadero\rad studio\7.0\include\../include/dinkumware/sstream#118
    0x0040B96B - c:\program files (x86)\embarcadero\rad studio\7.0\include\../include/dinkumware/streambuf#144
    0x0040AFC0 - c:\program files (x86)\embarcadero\rad studio\7.0\include\../include/dinkumware/streambuf#707
    0x0040B124 - c:\program files (x86)\embarcadero\rad studio\7.0\include\dinkumware\xlocnum#1547
    0x0040B299 - c:\program files (x86)\embarcadero\rad studio\7.0\include\dinkumware\xlocnum#1560

Richard Tresidder at 3/7/2011 11:33:52 PM -
bump...

Is this ever going to be fixed...
Now going on 4 years since this was reported..
People are still having problems..
Issue is present in latest C++ Builder XE

Tomohiro Takahashi at 3/8/2011 5:04:02 PM -
This is a comment from internal tracking system.
<<<<<<<<<<
The problem here is that CodeGuard doesn't work well with dynamic RTL since the code inside the DLL is already linked and won't get redirected to the CodeGuard wrappers.
>>>>>>>>>>

Niki Minkov at 9/1/2011 6:49:18 AM -
Disabling Dynamic RTL DOES NOT fix the issue!!!

Tomohiro Takahashi at 3/8/2011 4:52:50 AM -
Thanks for the notification. But, unfortunately, this issue is still Open....

totte karlsson at 4/29/2011 9:08:19 PM -
this is the serioust bug on mylist.. and it has been years since it appeared!

Server Response from: ETNACODE01