STL string problems

Started by
17 comments, last by jkleinecke 17 years, 8 months ago
  • What happens if you actually print out the contents of g_strSomeString before and after the call to AssignText?

  • What are your compiler settings?
Σnigma
Advertisement
Okay, now this is wierd. If I call 'c_str()' on the string it gives me back the proper information. So it looks like the problem is limited to working with just the stl string. For some reason I still can't assign a string to another string.
-----------------------------------Indium Studios, Inc.
Well, I know the problem exists in my project. I've tried a sandbox application and that works fine.

I'm using standard debug compile and linker settings. I don't really have the option of creating the project fresh because of the size of the codebase (34k lines).

It's unlikely that any of you are going to be able to help me debug the problem. However, I do appreciate the help and if anyone has seen an error like this before, any information you have could be helpful.

Thanks...
-----------------------------------Indium Studios, Inc.
Quote:Original post by jkleinecke
Well, I know the problem exists in my project. I've tried a sandbox application and that works fine.

This almost certainly means you have memory corruption in your project. Set a data watch on the memory which appears to be corrupted to find out where it's being modified.

Σnigma
While I don't doubt the memory issue, I don't really think it's a corruption problem. The problem just appeared in the codebase and it first shows up on the first memory allocation that takes place. It's definitely an issue with stl string memory allocation.
-----------------------------------Indium Studios, Inc.
I see Í in the MSVC debugger all the time. It means the memory wasn't initialized. In debug builds, everything is initialized to the hex value '0xCDCDCDCD'. 'CD' happens to be the ascii code for the character Í.
Ah, that makes sense. What doesn't make sense is why all my strings start 4 bytes into the string buffer...
-----------------------------------Indium Studios, Inc.
Could you possibly have incremented a value one-past-the-end of an array of int* values, such that the first 4 bytes of the string object got incremented by sizeof(int) == 4, where those bytes happen to represent the pointer-to-data in your compiler's std::string implementation? :s
While that's always a possibility, it's not likely to be the problem. I create a string to pass into my engine initialization, it's the first allocation and it's immediately wrong. My first guess was that it was a buffer overrun.

I have found a way around the problem though. I have my own memory manager and STL Allocator that plugs into the memory manager. The only STL type I hadn't wrapped was string so I went ahead and did that one as well. Strings are a little bit harder to get right, so it took some work. But after taking all weekend to implement it, I haven't seen that problem. Anyway, thank for all your help.
-----------------------------------Indium Studios, Inc.

This topic is closed to new replies.

Advertisement