BUG: FindIndex Works Incorrectly When nIndex Is Negative

Last reviewed: September 3, 1997
Article ID: Q173244
The information in this article applies to:
  • The Microsoft Foundation Classes (MFC) included with: - Microsoft Visual C++, 32-bit Editions, versions 2.0, 2.1, 2.2, 4.0,

         4.1, 4.2, 5.0
    

SYMPTOMS

If a value less that 0 is passed to the FindIndex function, the function will ASSERT in debug mode and enter an infinite loop in release mode.

CAUSE

The problem is that an ASSERT statement is used to test for a negative value in the FindIndex function instead of an if...then statement that would return NULL if the value is negative.

RESOLUTION

Check the value that is passed to FindIndex to make sure that it is not negative before calling the FindIndex function.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.

MORE INFORMATION

The documentation for the FindIndex function in the CList, CStringList, CPtrList, and CObList classes states that the return value is NULL if nIndex is negative or too large.

In release mode, the program may also generate the following application error:

   The instruction at 0x... referenced memory at "0x00000000".

The memory could not be "read".

REFERENCES

See AFXTEMPL.H for CList, LIST_S.cpp for CStringList, LIST_P.cpp for CPtrList, and LIST_O.cpp for CObList implementation details. The header file can be found in the in the ...\VC\mfc\include directory and the source files can be found in the ...\VC\mfc\src directory.

Keywords          : MfcMisc vcbuglist400 vcbuglist500
Technology        : kbMfc
Version           : WINDOWS NT:2.0,2.1,2.2,4.0,4.1,4.2,5.0
Platform          : NT WINDOWS
Issue type        : kbbug


================================================================================


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.

Last reviewed: September 3, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.