Re: Release build seg faults at vector.push_back above certain size, b

From: Severian (severian_at_chlamydia-is-not-a-flower.com)
Date: 03/16/05


Date: Wed, 16 Mar 2005 17:34:05 GMT

On Wed, 16 Mar 2005 08:15:05 -0800, "whocares"
<whocares@discussions.microsoft.com> wrote:

>hi everyone.
>
>i'm currently experiencing a strange problem under vc++ 2005 express. i hope
>someone has a hint for me, i'm kind of lost atm.
>
>i'm using a vectors of pointers in my code.
>using the release build i can add and remove elements aslong as i stay below
>a certain vector size (13 in this case, no joke). as soon as the vector tries
>to add element 14 i get a runtime error.
>
>the whole thing get's really strange when i use the debug build. i can add
>as much elements as i want without any problems (tried above 500). but that's
>not all. it works with the debug build aslong as i start from the IDE or if i
>doubleclick the debug.exe. it will crash with the same error as the release
>build when i start it from a cmd prompt (just one push_back earlier)
>
>i have no clue what to do now. i can't debug cause the debug build works.
>inserting some debug msgs show that vector.push_back() seems to trigger the
>crash...
>
>suggestions more than welcome

Running a debugger introduces extra data and code pages into your
process. So while the debugger is active, you're probably overwriting
some non-critical debug information, or reading some debug info or
code using invalid pointers.

My initial guess is that you're releasing a pointer while it's still
part of a vector and it's being reaccessed later.

To help during the build, set the warning level to 4 (/W4) and define
STRING (-DSTRICT) to detect some coding errors. Do not ignore any
warning unless you understand *exactly* why it can be ignored.

For running (debug or not), be sure all run-time checks are enabled.

Two other things that may help:

1) ero any pointer after you release it:

delete[] ptr;
ptr = NULL;

2) When declaring pointers, always initialize them to null:

OBJECT *ptr = NULL;

Good luck!

--
Sev


Relevant Pages

  • Re: strang behaviour std:vector and XString in VC6.0
    ... > In the debug version I've the following problem: ... > After I've added a couple of pointers using the push_back function and I ... > iterate over x the program crashes in the iteration loop. ... an uninitialised variable which happens to get one value in debug mode and a ...
    (comp.lang.cpp)
  • Re: Passing Smart Pointers as Parameters
    ... How do you obtain interface pointers on your own object? ... It's not the problem with the interfaces on my object. ... debug output... ... should see the debug output, ...
    (microsoft.public.vc.atl)
  • Re: Setting pointer to null!
    ... debug builds do not and AFAIK have never done that. ... yourself and initialise it NULL on a release build. ... and I think they use a repeated 0xCD pattern. ... if you "defensively" initialize all pointers to ...
    (microsoft.public.vc.language)
  • Re: strang behaviour std:vector and XString in VC6.0
    ... > In the debug version I've the following problem: ... > After I've added a couple of pointers using the push_back function and I ... > iterate over x the program crashes in the iteration loop. ... example of not more than 20 lines which uses no non-standard C++ ...
    (comp.lang.cpp)
  • Re: How to make (ptr + len) > lim safe?
    ... Meaning I use ptr < lim where ptr and lim are both pointers ... However, if ptr and lim both point into or one past the end of the same array, and if ptr < lim, then lim-ptr has to be positive, and that is something the standard does say. ... Not directly, but by inference from what it says about the binary '-' operator and the '<' operator, when acting on pointers: ...
    (comp.lang.c)

Quantcast