Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ffcccc
langcpp
{
  char data[BUFFERSIZE];
  char append_data[BUFFERSIZE];
  char *file_name;

  *// Initialize file_name and append_data */
  fstream file( file_name, fstream::in | fstream::out | fstream::app);
  file << append_data << ends;
  file >> data;
  // ...
} /*/ File gets closed here */

Compliant Solution (seekg)

...

Code Block
bgColor#ccccff
langcpp
{
  char data[BUFFERSIZE];
  char append_data[BUFFERSIZE];
  char *file_name;

  *// Initialize file_name and append_data */
  fstream file( file_name, fstream::in | fstream::out | fstream::app);
  file << append_data << ends;
	file.seekg(0, ios::beg);
  file >> data;
  // ...
} //* File gets closed here */

Risk Assessment

Alternately inputting and outputting from a stream without an intervening flush or positioning call is undefined behavior.

...