EDN Admin
Well-known member
<span style="font-family:Consolas; font-size:x-small <span style="font-family:Consolas; font-size:x-small
<div style="color:Black;background-color:White; <pre>
Im looking <span style="color:Blue; for some helpful suggestions about how to debug <span style="color:Blue; this problem.
I get <span style="color:#A31515; "First-chance exception at 0x01376e31 in InitUtil.exe: 0xC0000005: Access violation reading location 0x00000000."
Some background on the situation:
1) The code <span style="color:Blue; in the immediate area of the crash does work when called <span style="color:Blue; in very simple context, it only fails <span style="color:Blue; in a more complex situation.
2) It will fail every time, <span style="color:Blue; in exactly the same place.
3) The additional complexity has nested dialogs, lambda code, inheritance, and some use of pointers <span style="color:Blue; in classes.
4) The last user interaction was to press OK on a dialog which should start a process of reading the <span style="color:Blue; double string from a text box, and convert it
into a <span style="color:Blue; double member variable.
One function higher <span style="color:Blue; in the call stack, text is <span style="color:#A31515; "2.71":
<span style="color:Blue; double getDouble( <span style="color:Blue; int id )
{
std::string text= getText( id );
std::stringstream ss ( text );
<span style="color:Blue; double retv;
ss >> retv;
===> <span style="color:Blue; return retv;
}
- <span style="color:Blue; this 0x01414068 {dialogHwnd=0x00260552 controls=[12]({nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "elevation" ...},{nextId=1002 classOfItem=Edit textForItem=<span style="color:#A31515; "20" ...},{nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "height" ...},{nextId=1002 classOfItem=Edit textForItem=<span style="color:#A31515; "20" ...},{nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "ratio" ...},{nextId=1002 classOfItem=Edit textForItem=<span style="color:#A31515; "2.71" ...},{nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "fireplace" ...},{nextId=1002 classOfItem=Button textForItem=<span style="color:#A31515; "" ...},{nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "description" ...},{nextId=1002 classOfItem=Edit textForItem=<span style="color:#A31515; "Covered with ice, overlooking the bay." ...},{nextId=1002 classOfItem=Button textForItem=<span style="color:#A31515; "Cancel" ...},{nextId=1002 classOfItem=Button textForItem=<span style="color:#A31515; "OK" ...}) } ZX:ialog * <span style="color:Blue; const
+ dialogHwnd 0x00260552 {unused=??? } HWND__ *
+ controls [12]({nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "elevation" ...},{nextId=1002 classOfItem=Edit textForItem=<span style="color:#A31515; "20" ...},{nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "height" ...},{nextId=1002 classOfItem=Edit textForItem=<span style="color:#A31515; "20" ...},{nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "ratio" ...},{nextId=1002 classOfItem=Edit textForItem=<span style="color:#A31515; "2.71" ...},{nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "fireplace" ...},{nextId=1002 classOfItem=Button textForItem=<span style="color:#A31515; "" ...},{nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "description" ...},{nextId=1002 classOfItem=Edit textForItem=<span style="color:#A31515; "Covered with ice, overlooking the bay." ...},{nextId=1002 classOfItem=Button textForItem=<span style="color:#A31515; "Cancel" ...},{nextId=1002 classOfItem=Button textForItem=<span style="color:#A31515; "OK" ...}) std::vector<ZX:ialogControlBase,std::allocator<ZX:ialogControlBase> >
id 1005 <span style="color:Blue; int
- ss {_Stringbuffer={...} } std::basic_stringstream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char>,std::allocator<<span style="color:Blue; char> >
- std::basic_iostream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> > {...} std::basic_iostream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> >
+ std::basic_istream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> > {_Chcount=0 } std::basic_istream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> >
+ std::basic_ostream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> > {...} std::basic_ostream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> >
- _Stringbuffer {_Seekhigh=0x00b94dd4 <span style="color:#A31515; "ýýýý««««««««" _Mystate=1 _Al={...} } std::basic_stringbuf<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char>,std::allocator<<span style="color:Blue; char> >
+ std::basic_streambuf<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> > {_Mylock={...} _Gfirst=0x00b94dd0 <span style="color:#A31515; "2.71ýýýý««««««««" _Pfirst=0x00b94dd0 <span style="color:#A31515; "2.71ýýýý««««««««" ...} std::basic_streambuf<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> >
+ _Seekhigh 0x00b94dd4 <span style="color:#A31515; "ýýýý««««««««" <span style="color:Blue; char *
_Mystate 1 <span style="color:Blue; int
+ _Al {...} std::allocator<<span style="color:Blue; char>
retv -9.2559631349317831e+061 <span style="color:Blue; double
+ text <span style="color:#A31515; "2.71" std::basic_string<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char>,std::allocator<<span style="color:Blue; char> >
And then the exception occurs on <span style="color:Blue; this code at the <span style="color:#A31515; "====>"
_Myt& __CLR_OR_THIS_CALL <span style="color:Blue; operator>>(<span style="color:Blue; double& _Val)
{ <span style="color:Green; // extract a double
01376DC0 push ebp
01376DC1 mov ebp,esp
01376DC3 push 0FFFFFFFFh
01376DC5 push offset __ehhandler$??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AAN@Z (13E6923h)
01376DCA mov eax,dword ptr fs:[00000000h]
01376DD0 push eax
01376DD1 push ecx
01376DD2 sub esp,180h
01376DD8 push ebx
01376DD9 push esi
01376DDA push edi
01376DDB push ecx
01376DDC lea edi,[ebp-190h]
01376DE2 mov ecx,60h
01376DE7 mov eax,0CCCCCCCCh
01376DEC rep stos dword ptr es:[edi]
01376DEE pop ecx
01376DEF mov eax,dword ptr [___security_cookie (14124E8h)]
01376DF4 xor eax,ebp
01376DF6 push eax
01376DF7 lea eax,[ebp-0Ch]
01376DFA mov dword ptr fs:[00000000h],eax
01376E00 mov dword ptr [ebp-10h],esp
01376E03 mov dword ptr [ebp-18h],ecx
ios_base::iostate _State = ios_base::goodbit;
01376E06 mov dword ptr [ebp-24h],0
<span style="color:Blue; const sentry _Ok(*<span style="color:Blue; this);
01376E0D push 0
01376E0F mov eax,dword ptr [ebp-18h]
01376E12 push eax
01376E13 lea ecx,[ebp-34h]
01376E16 call std::basic_istream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> >::sentry::sentry (12F7FE0h)
01376E1B mov dword ptr [ebp-4],0
<span style="color:Blue; if (_Ok)
01376E22 lea eax,[ebp-170h]
01376E28 push eax
01376E29 lea ecx,[ebp-34h]
01376E2C call std::basic_istream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> >::sentry::<span style="color:Blue; operator <span style="color:Blue; int std::_Bool_struct::* (12F84CCh)
====> 01376E31 mov ecx,dword ptr [eax]
01376E33 mov dword ptr [ebp-184h],ecx
etc
The registers are:
EAX = 00000000 EBX = 00000001 ECX = 0037D60C EDX = 0037D60C ESI = 0037DAB8 EDI = 0037D630 EIP = 01376E31 ESP = 0037D49C EBP = 0037D640 EFL = 00010246
so it is no surprise that I get an error from reading from address 0.
The debugger shows these variables:
- <span style="color:Blue; this 0x0037d740 {_Chcount=0 } std::basic_istream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> > * <span style="color:Blue; const
- std::basic_ios<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> > {_Mystrbuf=0x0037d758 _Tiestr=0x00000000 _Fillch= } std::basic_ios<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> >
+ std::ios_base {_Stdstr=0 _Mystate=0 _Except=0 ...} std::ios_base
+ _Mystrbuf 0x0037d758 {_Seekhigh=0x00b94dd4 <span style="color:#A31515; "ýýýý««««««««" _Mystate=1 _Al={...} } std::basic_streambuf<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> > *
+ _Tiestr 0x00000000 std::basic_ostream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> > *
_Fillch 32 <span style="color:Blue; char
_Chcount 0 __int64
_Val -9.2559631349317831e+061 <span style="color:Blue; double &
+ _Ok {_Ok=<span style="color:Blue; true } std::basic_istream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> >::sentry
_State 0 <span style="color:Blue; int
So Im perplexed. Is <span style="color:Blue; this a stack or heap corruption problem? If so how does a local stringstream get into trouble?
Any debugging hints are welcome.
[/code]
<br/>
View the full article
<div style="color:Black;background-color:White; <pre>
Im looking <span style="color:Blue; for some helpful suggestions about how to debug <span style="color:Blue; this problem.
I get <span style="color:#A31515; "First-chance exception at 0x01376e31 in InitUtil.exe: 0xC0000005: Access violation reading location 0x00000000."
Some background on the situation:
1) The code <span style="color:Blue; in the immediate area of the crash does work when called <span style="color:Blue; in very simple context, it only fails <span style="color:Blue; in a more complex situation.
2) It will fail every time, <span style="color:Blue; in exactly the same place.
3) The additional complexity has nested dialogs, lambda code, inheritance, and some use of pointers <span style="color:Blue; in classes.
4) The last user interaction was to press OK on a dialog which should start a process of reading the <span style="color:Blue; double string from a text box, and convert it
into a <span style="color:Blue; double member variable.
One function higher <span style="color:Blue; in the call stack, text is <span style="color:#A31515; "2.71":
<span style="color:Blue; double getDouble( <span style="color:Blue; int id )
{
std::string text= getText( id );
std::stringstream ss ( text );
<span style="color:Blue; double retv;
ss >> retv;
===> <span style="color:Blue; return retv;
}
- <span style="color:Blue; this 0x01414068 {dialogHwnd=0x00260552 controls=[12]({nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "elevation" ...},{nextId=1002 classOfItem=Edit textForItem=<span style="color:#A31515; "20" ...},{nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "height" ...},{nextId=1002 classOfItem=Edit textForItem=<span style="color:#A31515; "20" ...},{nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "ratio" ...},{nextId=1002 classOfItem=Edit textForItem=<span style="color:#A31515; "2.71" ...},{nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "fireplace" ...},{nextId=1002 classOfItem=Button textForItem=<span style="color:#A31515; "" ...},{nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "description" ...},{nextId=1002 classOfItem=Edit textForItem=<span style="color:#A31515; "Covered with ice, overlooking the bay." ...},{nextId=1002 classOfItem=Button textForItem=<span style="color:#A31515; "Cancel" ...},{nextId=1002 classOfItem=Button textForItem=<span style="color:#A31515; "OK" ...}) } ZX:ialog * <span style="color:Blue; const
+ dialogHwnd 0x00260552 {unused=??? } HWND__ *
+ controls [12]({nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "elevation" ...},{nextId=1002 classOfItem=Edit textForItem=<span style="color:#A31515; "20" ...},{nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "height" ...},{nextId=1002 classOfItem=Edit textForItem=<span style="color:#A31515; "20" ...},{nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "ratio" ...},{nextId=1002 classOfItem=Edit textForItem=<span style="color:#A31515; "2.71" ...},{nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "fireplace" ...},{nextId=1002 classOfItem=Button textForItem=<span style="color:#A31515; "" ...},{nextId=1002 classOfItem=Static textForItem=<span style="color:#A31515; "description" ...},{nextId=1002 classOfItem=Edit textForItem=<span style="color:#A31515; "Covered with ice, overlooking the bay." ...},{nextId=1002 classOfItem=Button textForItem=<span style="color:#A31515; "Cancel" ...},{nextId=1002 classOfItem=Button textForItem=<span style="color:#A31515; "OK" ...}) std::vector<ZX:ialogControlBase,std::allocator<ZX:ialogControlBase> >
id 1005 <span style="color:Blue; int
- ss {_Stringbuffer={...} } std::basic_stringstream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char>,std::allocator<<span style="color:Blue; char> >
- std::basic_iostream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> > {...} std::basic_iostream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> >
+ std::basic_istream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> > {_Chcount=0 } std::basic_istream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> >
+ std::basic_ostream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> > {...} std::basic_ostream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> >
- _Stringbuffer {_Seekhigh=0x00b94dd4 <span style="color:#A31515; "ýýýý««««««««" _Mystate=1 _Al={...} } std::basic_stringbuf<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char>,std::allocator<<span style="color:Blue; char> >
+ std::basic_streambuf<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> > {_Mylock={...} _Gfirst=0x00b94dd0 <span style="color:#A31515; "2.71ýýýý««««««««" _Pfirst=0x00b94dd0 <span style="color:#A31515; "2.71ýýýý««««««««" ...} std::basic_streambuf<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> >
+ _Seekhigh 0x00b94dd4 <span style="color:#A31515; "ýýýý««««««««" <span style="color:Blue; char *
_Mystate 1 <span style="color:Blue; int
+ _Al {...} std::allocator<<span style="color:Blue; char>
retv -9.2559631349317831e+061 <span style="color:Blue; double
+ text <span style="color:#A31515; "2.71" std::basic_string<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char>,std::allocator<<span style="color:Blue; char> >
And then the exception occurs on <span style="color:Blue; this code at the <span style="color:#A31515; "====>"
_Myt& __CLR_OR_THIS_CALL <span style="color:Blue; operator>>(<span style="color:Blue; double& _Val)
{ <span style="color:Green; // extract a double
01376DC0 push ebp
01376DC1 mov ebp,esp
01376DC3 push 0FFFFFFFFh
01376DC5 push offset __ehhandler$??5?$basic_istream@DU?$char_traits@D@std@@@std@@QAEAAV01@AAN@Z (13E6923h)
01376DCA mov eax,dword ptr fs:[00000000h]
01376DD0 push eax
01376DD1 push ecx
01376DD2 sub esp,180h
01376DD8 push ebx
01376DD9 push esi
01376DDA push edi
01376DDB push ecx
01376DDC lea edi,[ebp-190h]
01376DE2 mov ecx,60h
01376DE7 mov eax,0CCCCCCCCh
01376DEC rep stos dword ptr es:[edi]
01376DEE pop ecx
01376DEF mov eax,dword ptr [___security_cookie (14124E8h)]
01376DF4 xor eax,ebp
01376DF6 push eax
01376DF7 lea eax,[ebp-0Ch]
01376DFA mov dword ptr fs:[00000000h],eax
01376E00 mov dword ptr [ebp-10h],esp
01376E03 mov dword ptr [ebp-18h],ecx
ios_base::iostate _State = ios_base::goodbit;
01376E06 mov dword ptr [ebp-24h],0
<span style="color:Blue; const sentry _Ok(*<span style="color:Blue; this);
01376E0D push 0
01376E0F mov eax,dword ptr [ebp-18h]
01376E12 push eax
01376E13 lea ecx,[ebp-34h]
01376E16 call std::basic_istream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> >::sentry::sentry (12F7FE0h)
01376E1B mov dword ptr [ebp-4],0
<span style="color:Blue; if (_Ok)
01376E22 lea eax,[ebp-170h]
01376E28 push eax
01376E29 lea ecx,[ebp-34h]
01376E2C call std::basic_istream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> >::sentry::<span style="color:Blue; operator <span style="color:Blue; int std::_Bool_struct::* (12F84CCh)
====> 01376E31 mov ecx,dword ptr [eax]
01376E33 mov dword ptr [ebp-184h],ecx
etc
The registers are:
EAX = 00000000 EBX = 00000001 ECX = 0037D60C EDX = 0037D60C ESI = 0037DAB8 EDI = 0037D630 EIP = 01376E31 ESP = 0037D49C EBP = 0037D640 EFL = 00010246
so it is no surprise that I get an error from reading from address 0.
The debugger shows these variables:
- <span style="color:Blue; this 0x0037d740 {_Chcount=0 } std::basic_istream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> > * <span style="color:Blue; const
- std::basic_ios<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> > {_Mystrbuf=0x0037d758 _Tiestr=0x00000000 _Fillch= } std::basic_ios<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> >
+ std::ios_base {_Stdstr=0 _Mystate=0 _Except=0 ...} std::ios_base
+ _Mystrbuf 0x0037d758 {_Seekhigh=0x00b94dd4 <span style="color:#A31515; "ýýýý««««««««" _Mystate=1 _Al={...} } std::basic_streambuf<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> > *
+ _Tiestr 0x00000000 std::basic_ostream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> > *
_Fillch 32 <span style="color:Blue; char
_Chcount 0 __int64
_Val -9.2559631349317831e+061 <span style="color:Blue; double &
+ _Ok {_Ok=<span style="color:Blue; true } std::basic_istream<<span style="color:Blue; char,std::char_traits<<span style="color:Blue; char> >::sentry
_State 0 <span style="color:Blue; int
So Im perplexed. Is <span style="color:Blue; this a stack or heap corruption problem? If so how does a local stringstream get into trouble?
Any debugging hints are welcome.
[/code]
<br/>
View the full article