Microsoft KB Archive/184236

= BUG: Filebuf overflow and underflow Call filebuf::sync =

Article ID: 184236

Article Last Modified on 1/6/2004

-

APPLIES TO


 * Microsoft Visual C++ 4.0 Standard Edition
 * Microsoft Visual C++ 4.0 Standard Edition
 * Microsoft Visual C++ 4.1 Subscription
 * Microsoft Visual C++ 4.2 Enterprise Edition
 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 4.2 Professional Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition
 * Microsoft Visual C++ .NET 2003 Standard Edition
 * Microsoft Visual C++ .NET 2002 Standard Edition

-



This article was previously published under Q184236



SYMPTOMS
The filebuf class allows you to use buffered file input/output (I/O), and provides the sync function to flush the file buffers. However, the filebuf::overflow and filebuf::underflow functions do not support the use of virtual functions in the filebuf class. Classes derived from filebuf might incorrectly call filebuf::sync when they should call the sync function from the derived class.



CAUSE
The filebuf class calls filebuf::sync instead of calling sync.



RESOLUTION
You can use one of the following workarounds to this problem:  Do not define the virtual function sync in your filebuf-derived class.

-or-

define your own versions of overflow and underflow in the derived class.  Change the filebuf::overflow and filebuf::underflow functions to call sync instead of filebuf::sync. You can find the source code for filebuf class functions in the following location: ...\VC\Src\FileBuf.cpp The source code for filebuf::overflow follows: int filebuf::overflow(int c)     { if (allocate==EOF) return EOF; if (filebuf::sync==EOF) // Change to sync for the workaround. return EOF;

if (!unbuffered) setp(base,ebuf); if (c!=EOF) {             if ((!unbuffered) && (pptr < epptr)) sputc(c); else {                 if (_write(x_fd,&c,1)!=1) return(EOF); }             }          return(1); } 



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.



MORE INFORMATION
Additional query words: inheritance inherit

Keywords: kbbug kblangcpp kbpending kbcode KB184236

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.