AfxIsValidString does not seem to work.
-
char szDescription[200]; BOOL bValid; bValid= AfxIsValidString(szDescription, 400); //bValid is TRUE, shouldn't it be FALSE?????????/ thanks
McGahanFL wrote: ...shouldn't it be FALSE?????????/ What makes you think so? This function tests the memory address to ensure that it is contained entirely within the program’s memory space.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
McGahanFL wrote: ...shouldn't it be FALSE?????????/ What makes you think so? This function tests the memory address to ensure that it is contained entirely within the program’s memory space.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
DavidCrow wrote: This function tests the memory address to ensure that it is contained entirely within the program’s memory space. I thought this was
AfxIsValidAddress()
, or maybe does AfsIsValidString callAfxIsValidAddress()
? Anyway, I can understand that defining a string of 200 chars, and getting true when checking if it is valid for 400 chars is a bit disturbing, especially since the MSDN states : Nonzero if the specified pointer points to a string of the specified size; otherwise 0. ~RaGE(); -
DavidCrow wrote: This function tests the memory address to ensure that it is contained entirely within the program’s memory space. I thought this was
AfxIsValidAddress()
, or maybe does AfsIsValidString callAfxIsValidAddress()
? Anyway, I can understand that defining a string of 200 chars, and getting true when checking if it is valid for 400 chars is a bit disturbing, especially since the MSDN states : Nonzero if the specified pointer points to a string of the specified size; otherwise 0. ~RaGE();I hate it when that happens. I was looking at
AfxIsValidString()
on my local MSDN, but then somehow started looking atAfxIsValidAddress()
on MSDN online. Thanks.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
I hate it when that happens. I was looking at
AfxIsValidString()
on my local MSDN, but then somehow started looking atAfxIsValidAddress()
on MSDN online. Thanks.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
DavidCrow wrote: This function tests the memory address to ensure that it is contained entirely within the program’s memory space. I thought this was
AfxIsValidAddress()
, or maybe does AfsIsValidString callAfxIsValidAddress()
? Anyway, I can understand that defining a string of 200 chars, and getting true when checking if it is valid for 400 chars is a bit disturbing, especially since the MSDN states : Nonzero if the specified pointer points to a string of the specified size; otherwise 0. ~RaGE(); -
char szDescription[200]; BOOL bValid; bValid= AfxIsValidString(szDescription, 400); //bValid is TRUE, shouldn't it be FALSE?????????/ thanks
Well, what is IN the szDescription, since you did not initialize it to anything? There might be at least one NUL byte within the 400 or so off the stack, in which case the 'length' of the string was less than or equal to 400 bytes. So the test passed, this time... I would not ever use AfxIsValidSring unless you had actually placed (or at least suspected one had been) a zero-terminated string into the variable first.
-
Well, what is IN the szDescription, since you did not initialize it to anything? There might be at least one NUL byte within the 400 or so off the stack, in which case the 'length' of the string was less than or equal to 400 bytes. So the test passed, this time... I would not ever use AfxIsValidSring unless you had actually placed (or at least suspected one had been) a zero-terminated string into the variable first.
-
char szDescription[200]; BOOL bValid; bValid= AfxIsValidString(szDescription, 400); //bValid is TRUE, shouldn't it be FALSE?????????/ thanks
AfxIsValidString can only verify that the string is readable. If you happen to pass in garbage that contains no \0 character, then it will return an error. However, in your case, even if there were no \0 characters in the first 200 bytes, the memory past the end of the string is probably readable and thus will not generate an error. Tim Smith I'm going to patent thought. I have yet to see any prior art.
-
AfxIsValidString can only verify that the string is readable. If you happen to pass in garbage that contains no \0 character, then it will return an error. However, in your case, even if there were no \0 characters in the first 200 bytes, the memory past the end of the string is probably readable and thus will not generate an error. Tim Smith I'm going to patent thought. I have yet to see any prior art.