ID: Q113535
1.00 WINDOWS kbprg kbfixlist kbbuglist
The information in this article applies to:
- Microsoft Visual C++ for Windows, version 1.0
Calling AfxIsValidString() with a near NULL pointer results in a TRUE return value. The return value should be FALSE because a NULL pointer is invalid.
For example, consider the following code:
char NEAR * npszEmpty = NULL;
ASSERT(AfxIsValidString(npszEmpty));
This should cause the assertion to fail but doesn't.
AfxIsValidString() takes an LPCSTR, which is defined in WINDOWS.H as:
typedef const char FAR* LPCSTR; // far pointer to a read-only string
Therefore, the "char NEAR *" parameter is first converted to a LPCSTR or
FAR pointer, which changes it from an offset-only value of 0x0000 to a
selector:offset value of DS:0x0000. This value will not evaluate to NULL
because the data segment register will most likely contain a nonzero value.
To work around this problem, do one of the following:
char NEAR * npszEmpty = NULL;
ASSERT(npszEmpty != NULL && AfxIsValidString(npszEmpty));
Microsoft has confirmed this to be a problem in the Microsoft Foundation Classes version 2.0. This problem was corrected in the Microsoft Foundation Classes version 2.5.
Additional reference words: 1.00 2.00 return valid pointer KBCategory: kbprg kbfixlist kbbuglist KBSubcategory: MfcMisc
Keywords : kb16bitonly kbnokeyword kbMFC kbVC kbbuglist kbfixlist
Version : 1.00
Platform : WINDOWS
Solution Type : kbfix
Last Reviewed: September 21, 1997