From: Frank Perry on
Howdy,

I'm having a problem with CString. Rarely but too often, GetLength returns
the wrong length. A recent example is a CString "OR" returned a length of
0xDD000002. As you could guess, this caused Serialize to have a heartattack.

Has anyone seen this kind of problem before and have an idea of the cause
and of a solution?

--
Frank Perry
LavaLeaf Software
From: David Wilkinson on
Frank Perry wrote:
> Howdy,
>
> I'm having a problem with CString. Rarely but too often, GetLength returns
> the wrong length. A recent example is a CString "OR" returned a length of
> 0xDD000002. As you could guess, this caused Serialize to have a heartattack.
>
> Has anyone seen this kind of problem before and have an idea of the cause
> and of a solution?

If your app is Unicode, I hope you used L"OR" or _T("OR").

--
David Wilkinson
Visual C++ MVP
From: Tom Serface on
I've never seen this, but you could try tracing down into the GetLength()
function to see what it is looking at. That string looks innocent enough.
Even if you were using Unicode it would have just stored it as ASCII so it
might not have been what you wanted, but it still should have worked.

Tom

"Frank Perry" <FrankPerry(a)discussions.microsoft.com> wrote in message
news:D96766AC-B5BE-40D4-AA6C-BB489965C511(a)microsoft.com...
> Howdy,
>
> I'm having a problem with CString. Rarely but too often, GetLength
> returns
> the wrong length. A recent example is a CString "OR" returned a length of
> 0xDD000002. As you could guess, this caused Serialize to have a
> heartattack.
>
> Has anyone seen this kind of problem before and have an idea of the cause
> and of a solution?
>
> --
> Frank Perry
> LavaLeaf Software

From: Joseph M. Newcomer on
Under normal conditions this is not possible.

You would need to show the code, as a start.

It could also be a memory clobber by the block of memory preceding the CString overwriting
its space and clobbering the data, or a data underrun if you ever unwrap the string
representation. There are a huge number of explanations, but there is insufficient
context to determine which one might apply.

Consider the following questions:
Have you ever done a GetBuffer/ReleaseBuffer on this string?
Have you ever done a GetBuffer/ReleaseBuffer on any string?
Do you have any data structure with a fixed-size array of anything in it?

That's just a start.
joe

On Wed, 6 Jan 2010 09:13:02 -0800, Frank Perry <FrankPerry(a)discussions.microsoft.com>
wrote:

>Howdy,
>
>I'm having a problem with CString. Rarely but too often, GetLength returns
>the wrong length. A recent example is a CString "OR" returned a length of
>0xDD000002. As you could guess, this caused Serialize to have a heartattack.
>
>Has anyone seen this kind of problem before and have an idea of the cause
>and of a solution?
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Frank Perry on
Howdy,

I'll try and cover several questions.

The program is not Unicode.

The CString in the case here could be generated one of serveral ways. The
most likey is:
const char *DefOperators[] =
{
"OR",
"AND",
"ADJ",
"NEAR",
"WITH",
"SAME"
};

CString ValidateDefOperator(CString Value)
{
Value.MakeUpper();
int Size = sizeof(DefOperators)/sizeof(DefOperators[0]);
for(int i=0; i<Size; i++)
if(DefOperators[i] == Value)
return Value;
return "OR";
}
When it comes from some other source, it will be processed here so the end
result would be the same.

I can't trace it because it is a rare occurrence. I'm afraid that logic is
about all I can apply to the problem.

I don't see instances of GetBuffer applied to the string in question. The
data is a class variable. If something is clobbering the string, it will be
almost impossible to sort out of the hundreds of C++ files that make up the
code.

One reason for asking about this is I had a similar problem show up when a
CString was being returned from or Oracle ODBC driver. That would sometimes
return a bad length for the string in a field of the rowset. It was returned
from the driver with a problem before anything in the program itself touched
it. I was wondering if this was similar.

The string itself is corrupted because the serialized data for it is FF FF
FF 02 00 00 DD, which indicates it was returned to the serialize string
function as 0xDD000002 bytes long.

--
Frank Perry
LavaLeaf Software


"Frank Perry" wrote:

> Howdy,
>
> I'm having a problem with CString. Rarely but too often, GetLength returns
> the wrong length. A recent example is a CString "OR" returned a length of
> 0xDD000002. As you could guess, this caused Serialize to have a heartattack.
>
> Has anyone seen this kind of problem before and have an idea of the cause
> and of a solution?
>
> --
> Frank Perry
> LavaLeaf Software