DOCUMENT:Q184236 07-FEB-2002 [visualc] TITLE :BUG: Filebuf overflow() and underflow() Call filebuf::sync() PRODUCT :Microsoft C Compiler PROD/VER::4.0,4.0a,4.1,4.2,5.0,6.0 OPER/SYS: KEYWORDS:kbcode kbLangCPP kbVC kbVC400bug kbVC410bug kbVC420bug kbVC500bug kbVC600bug ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual C++, versions 4.0, 4.0a, 4.1 - Microsoft Visual C++, 32-bit Enterprise Edition, versions 4.2, 5.0, 6.0 - Microsoft Visual C++, 32-bit Professional Edition, versions 4.2, 5.0, 6.0 - Microsoft Visual C++, 32-bit Learning Edition, version 6.0 - Microsoft Visual C++.NET (2002) ------------------------------------------------------------------------------- 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 ================ (c) Microsoft Corporation 1999, All Rights Reserved. Contributions by Mark Hagen, Microsoft Corporation Additional query words: inheritance inherit ====================================================================== Keywords : kbcode kbLangCPP kbVC kbVC400bug kbVC410bug kbVC420bug kbVC500bug kbVC600bug Technology : kbVCsearch kbVC400 kbAudDeveloper kbVC410 kbVC420 kbVC500 kbVC600 kbVC32bitSearch kbVC400a kbVCNET kbVC500Search Version : :4.0,4.0a,4.1,4.2,5.0,6.0 Issue type : kbbug Solution Type : kbpending ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 2002.