Microsoft KB Archive/23753

{|
 * width="100%"|

PRB: fseek Function Moves to Unexpected Location in File
'Article ID: Q23753

Creation Date: 16-DEC-1987

Revision Date: 18-DEC-1995' The information in this article applies to:

  The C Run-time (CRT), included with: - Microsoft C for MS-DOS, versions 5.1, 6.0, 6.0a, and 6.0ax - Microsoft C for OS/2, versions 5.1, 6.0, and 6.0a - Microsoft C/C++ for MS-DOS, version 7.0 - Microsoft Visual C++ for Windows, versions 1.0 and 1.5 - Microsoft Visual C++ 32-bit Edition, versions 1.0, 2.0, and 4.0 SYMPTOMS

An attempt to use the fseek function fails when an application points to a location in the file other than that desired. CAUSE

The application specifies a 16-bit "int" value as the second parameter to the fseek function. RESOLUTION

Specify a "long" value as the second parameter to the fseek function. MORE INFORMATION

The maximum value of a signed 16-bit "int" value is 32,767 (32K). With a signed 16-bit int, a value between 32K and 64K is treated as negative. If an application specifies a 16-bit "int" as the second parameter to the fseek function, the compiler automatically casts it to a "long." However, when this occurs, the value is sign-extended. Therefore, a 16- bit "int" value between 32K and 64K is sign-extended as a negative "long" value, which produces unexpected results when seeking in a file. In the Windows NT operating system, an "int" is 32-bits in size, the same as a "long." Therefore, this problem occurs on Windows NT only when the data type of the second parameter to the fseek function is declared as a "short int," a 16-bit value. 
 * }

-

"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." '' ©1997 Microsoft Corporation. All rights reserved. Legal Notices.

''

Additional reference words: 1.00 1.50 2.00 5.10 6.00 6.00a 6.00ax 7.00 4.00

KBCategory: kbprg kbfasttip kbprb

KBSubcategory: CRTIss