Re: Crashes in Debug (random) but not release

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Thu, 14 Apr 2005 17:35:23 -0400, r_z_aret@xxxxxxxxxxxx wrote:

>On Wed, 13 Apr 2005 08:57:47 -0600, "Timothy Dean"
><tim.dean@xxxxxxxxxxxxxxxxxxx> wrote:

clip

Another tool that I've found helpful is lint. Sure doesn't eliminate
all the bugs. Sure is a bother to use (like having a _very_ fussy
editor check your writing). But every little bit helps.


>>Another thing I noticed at one point when calling a function with a
>>parameter passed by value. The parameter is passed as a contant string (ex:
>>functionCall("SomeText")). When looking at the constructor of the parameter
>>object that takes the string, an invalid pointer arrives at the copy
>>constructor. Thats something I have no control over, right? It is like the
>>string table is corrupt at that point.
>
>Who wrote the constructor? Are you sure the object being constructed
>is appropriate? If you let the compiler choose the appropriate
>conversion, it might make a bad choice. Try doing the conversion
>explicitly (add a variable of the type required for the function, set
>it to the variable you want to pass) and step through the code to see
>what really happens.

Also, make sure any arguments passed to the constructor(s) are valid.
I just caught myself writing a function that returned a pointer to a
stack variable. That caused a serious hiccup in the constructor that
was supposed to handle the pointer.

>
>>
>>Timothy Dean
>>MobileDataforce.
>>
>>
>><r_z_aret@xxxxxxxxxxxx> wrote in message
>>news:ag7o51pqsvq8pe322h5nbeav78kkk15191@xxxxxxxxxx
>>> On Tue, 12 Apr 2005 10:54:37 -0600, "Timothy Dean"
>>> <tim.dean@xxxxxxxxxxxxxxxxxxx> wrote:
>>>
>>> >I have an issue when running in debug mode, the program will "crash" with
>>> >either the "data misalignment" or "access violation" errors. When I run
>>it
>>> >in release, everthing seems fine. The other odd thing is that the place
>>it
>>> >crashes in debug mode seems random. Sometimes if I execute a particular
>>> >line with
>>> >"F10", it will throw the exception. The next time, if I hit "F5" past
>>the
>>> >same line, or "F11" and step through it won't crash at all, or it will
>>crash
>>> >in a different place. If I change a piece of source code, recompile, and
>>> >run again, it will crash in a
>>> >different spot. It seems like the executable file or maybe a library
>>that I
>>> >am linking in is corrupt or misaligned when generating a debug build. Is
>>> >this possible? Has anyone seen anything similar? Thanks.
>>>
>>> Every month or so, someone asks for help trying to figure out why a
>>> program crashes when built for release but not debug or vice versa. So
>>> google _would_ provide some info, except that the question is posed in
>>> so many different ways that finding a good search string is tough.
>>> Probably worth some effort anyway.
>>>
>>> At a minimum, I suggest checking a thread called "Debug works, Release
>>> hangs" in microsoft.public.windowsce.embedded this week.
>>>
>>> The cause is almost always a problem with the poster's code - probably
>>> a bad pointer. The variable symptoms in your case sound especially
>>> like a bad pointer. Unfortunately, the usual solution is a lot of
>>> grunt work to track down the problem. Add ASSERTs to test pointers and
>>> array indeces right after you set them and right before you use them;
>>> these will help find the actual problem. Use the debugger and add
>>> break points (and/or display message boxes), and move them closer and
>>> closer until you narrow down the symptom. Take deep breaths, etc. to
>>> calm down and clear your head. Repeat.
>>>
>>> Good luck.
>>>
>>>
>>> >
>>> >Timothy Dean
>>> >MobileDataforce
>>> >
>>> >
>>>
>>> -----------------------------------------
>>> To reply to me, remove the underscores (_) from my email address (and
>>please indicate which newsgroup and message).
>>>
>>> Robert E. Zaret, eMVP
>>> PenFact, Inc.
>>> 500 Harrison Ave., Suite 3R
>>> Boston, MA 02118
>>> www.penfact.com
>>
>
>-----------------------------------------
>To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).
>
>Robert E. Zaret, eMVP
>PenFact, Inc.
>500 Harrison Ave., Suite 3R
>Boston, MA 02118
>www.penfact.com

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
500 Harrison Ave., Suite 3R
Boston, MA 02118
www.penfact.com
.



Relevant Pages

  • Re: Strange EAccessViolation which I cannot figure out...
    ... where in your code you are freeing and setting it to NIL to then later ... The proper way is to always create it in the constructor or, ... type cast around this returned value as a pointer to a pchar string. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Arrays of Class Objects
    ... > In your original constructor one had to pass a 'string'. ... The compiler cannot create an Element Object from a string literal ... Element(const char* arg) ... When you are assigning a pointer to std::string you need to make sure ...
    (alt.comp.lang.learn.c-cpp)
  • Re: basic_string ctor
    ... >> They're not the same in C, which has no real concept of a string. ... > situations is regarded as an invalid pointer for all types. ... pointer is entirely up to the object's constructor to decide. ... learn and safer for most programmers to use if there was less undefined ...
    (microsoft.public.vc.stl)
  • Re: basic_string ctor
    ... I'm sure 10's of 1000's of C++ programmers have designed classes that take a pointer paramter to their constructor and provide some reasonable default behavior if the pointer is null. ... I can think of a few times you might want to convert a NULL to a std::string, but IMO those cases are all moot because you want to differentiate between an empty string and a null string. ... No function should allow null unless there is a good reason or at least a very well-definined and intuitive reason to allow nulls. ...
    (microsoft.public.vc.stl)
  • Re: Efficency and the standard library
    ... loop will dereference a null pointer if argument strInstring is ... this code, out of adversarial hatred, envy and malice. ... Some C programmers in these threads would suggest const ... the output string. ...
    (comp.lang.c)