Microsoft KB Archive/173244

= FIX: FindIndex Works Incorrectly When nIndex Is Negative =

Article ID: 173244

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 2.0 Professional Edition

 Microsoft Visual C++ 2.1

 Microsoft Visual C++ 2.2

 Microsoft Visual C++ 4.0 Standard Edition</li></ul>

 Microsoft Visual C++ 4.1 Subscription</li></ul>

 Microsoft Visual C++ 4.2 Enterprise Edition</li></ul>

 Microsoft Visual C++ 4.2 Professional Edition</li></ul>

 Microsoft Visual C++ 5.0 Enterprise Edition</li></ul>

 Microsoft Visual C++ 5.0 Professional Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q173244

<div class="symptoms_section">

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

<div class="cause_section">

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.

<div class="resolution_section">

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

<div class="status_section">

STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This problem was corrected in Visual C++ version 6.0.

<div class="moreinformation_section">

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:

<pre class="fixed_text">  The instruction at 0x... referenced memory at "0x00000000". The memory could not be "read".

<div class="references_section">