2

このソースコードの何が問題になっていますか?

#include <iostream>
#include <ostream>
#include <fstream>

void printTest ( std::ostream * o )
{
    *o << "test" << std::endl;
}


int main ( int argc, char * argv[] )
{
  std::ostream * o = &std::cout;
  char ot[4096];
  strcpy ( ot, "test.txt" );
  strcat ( ot, ".log" );
  static std::ofstream of ( ot );
  printTest ( o );  //Print to console OK
  o = & of;
  printTest ( o );  //Print to file: CodeGuard stops the application with the error log
  return 0;
}

このソースコードをCBuilder2010(CodeGuardが有効)でコンパイルしようとしました。アプリケーションはCodeGuardによって停止され、次のエラーログが表示されます。

25.12.2011 13:00:57 started a CodeGuard(tm) process: Project3.exe(2244)  
Bad parameter in process: Project3.exe(2244)  - c:\program files\embarcadero\rad studio\7.0\include\../include/dinkumware/fstream#55
A bad file or pipe stream (0x32AF36D4) has been passed to the function.
0x0040A150 Call to fputc(0x74 ['t'], 0x32AF36D4)
0x004098A5 - c:\program files\embarcadero\rad studio\7.0\include\../include/dinkumware/fstream#55
0x004081BE - c:\program files\embarcadero\rad studio\7.0\include\../include/dinkumware/fstream#246
0x00407E2B - c:\program files\embarcadero\rad studio\7.0\include\../include/dinkumware/streambuf#465
0x004020AD - c:\program files\embarcadero\rad studio\7.0\include\../include/dinkumware/streambuf#151
0x00401434 - c:\program files\embarcadero\rad studio\7.0\include\../include/dinkumware/ostream#683
0x00401276 - File3.cpp#13
Pointer arithmetic underrun in process: Project3.exe(2244)  - c:\program files\embarcadero\rad studio\7.0\include\../include/dinkumware/streambuf#207
0x00892501-512, that is at offset 1-512 in heap block 0x00892500 (size 512).
0x0040985E - c:\program files\embarcadero\rad studio\7.0\include\../include/dinkumware/streambuf#207
0x00408127 - c:\program files\embarcadero\rad studio\7.0\include\../include/dinkumware/fstream#237
0x00407E2B - c:\program files\embarcadero\rad studio\7.0\include\../include/dinkumware/streambuf#465
0x004020AD - c:\program files\embarcadero\rad studio\7.0\include\../include/dinkumware/streambuf#151
0x00401434 - c:\program files\embarcadero\rad studio\7.0\include\../include/dinkumware/ostream#683
0x00401276 - File3.cpp#13
The memory block (0x008922F0) [size: 512 bytes] was allocated with calloc
0x32A9D14F
0x004057B7 - c:\program files\embarcadero\rad studio\7.0\include\dinkumware\xlocale#1289
0x00404DDA - c:\program files\embarcadero\rad studio\7.0\include\dinkumware\xlocale#1261
0x004041F1 - c:\program files\embarcadero\rad studio\7.0\include\dinkumware\xlocale#1268
0x00403395 - c:\program files\embarcadero\rad studio\7.0\include\dinkumware\xlocale#323
0x004022AB - c:\program files\embarcadero\rad studio\7.0\include\../include/dinkumware

ご協力いただきありがとうございます。

更新された質問:

残念ながら、これは古くて報告されているバグです: http ://www.borlandtalk.com/is-there-a-bug-in-codeguard--vt112810.html

トピックを閉じることができます...

4

1 に答える 1

1

ランタイムに対して静的にリンクして、プロジェクトをビルドしてみてください。以下のオプションのチェックを外すことでそれを行うことができます:

C ++ Builder 2007

于 2011-12-25T12:36:14.463 に答える