Opened 13 months ago

Closed 13 months ago

Last modified 13 months ago

#15665 closed defect (fixed)

wxStaticText::SetLabel( wxT("&") ) Crashes

Reported by: ZaneUJi Owned by:
Priority: normal Milestone:
Component: GUI-all Version: 3.0.0
Keywords: Cc:
Blocked By: Blocking:
Patch: no

Description

Test case:

--- E:/wxWidgets-3.0.0/samples/controls/controls0.cpp	Tue Nov 12 23:22:48 2013
+++ E:/wxWidgets-3.0.0/samples/controls/controls.cpp	Tue Nov 12 23:14:20 2013
@@ -924,6 +924,7 @@
                             wxSize(240, wxDefaultCoord)
                           );
 #endif
+    m_wrappingText->SetLabel( wxT("&") );
     wrapping_sizer->Add( m_wrappingText );
 
     wxStaticBoxSizer *non_wrapping_sizer = new wxStaticBoxSizer( wxVERTICAL, panel, wxT("Non-wrapping") );

gdb information:

warning: Invalid menu string '&'


Program received signal SIGSEGV, Segmentation fault.
0x0078350e in wxStringOperationsWchar::DecodeChar (
    i=<error reading variable: Cannot access memory at address 0x4ff657e>)
    at ../../include/wx/stringops.h:52
52              { return *i; }
(gdb) bt
#0  0x0078350e in wxStringOperationsWchar::DecodeChar (
    i=<error reading variable: Cannot access memory at address 0x4ff657e>)
    at ../../include/wx/stringops.h:52
#1  0x007ccb04 in wxString::const_iterator::operator* (this=0x22e85c)
    at ../../include/wx/string.h:1071
#2  0x004f5de6 in wxStripMenuCodes (in=..., flags=1)
    at ../../src/common/utilscmn.cpp:1199
#3  0x00442538 in wxControlBase::GetLabelText (label=...)
    at ../../src/common/ctrlcmn.cpp:161
#4  0x007b92c6 in wxControlBase::GetLabelText (this=0x4fb6618)
    at ./../../include/wx/control.h:94
#5  0x00478cc4 in wxStaticText::DoGetBestClientSize (this=0x4fb6618)
    at ../../src/msw/stattext.cpp:106
#6  0x004b0502 in wxWindowBase::GetBestSize (this=0x4fb6618)
    at ../../src/common/wincmn.cpp:910
#7  0x0043051f in wxWindow::DoSetSize (this=0x4fb6618, x=0, y=0, width=-1,
    height=-1, sizeFlags=3) at ../../src/msw/window.cpp:2024
#8  0x00478ed1 in wxStaticText::DoSetSize (this=0x4fb6618, x=-1, y=-1, w=-1,
    h=-1, sizeFlags=3) at ../../src/msw/stattext.cpp:134
#9  0x0047921f in wxStaticText::SetLabel (this=0x4fb6618, label=...)
    at ../../src/msw/stattext.cpp:196
#10 0x004065d5 in MyPanel::MyPanel (this=0x4fa6da8, frame=0x4fa1cc8, x=10,
    y=10, w=300, h=100) at controls.cpp:927
#11 0x00413aee in MyFrame::MyFrame (this=0x4fa1cc8,
    title=0x7ea938 <_ZplRK8wxStringw+8300856> L"Controls wxWidgets App",
    x=50, y=50) at controls.cpp:1890
#12 0x004017f8 in MyApp::OnInit (this=0x427c328) at controls.cpp:421
#13 0x0075ab16 in wxAppConsoleBase::CallOnInit (this=0x427c328)
    at ./../../include/wx/app.h:93
#14 0x0064ff36 in wxEntryReal (argc=@0x8ae7d0: 1, argv=0x4f970e8)
    at ../../src/common/init.cpp:479
#15 0x00629308 in wxEntry (argc=@0x8ae7d0: 1, argv=0x4f970e8)
    at ../../src/msw/main.cpp:197
#16 0x004e17eb in wxEntry (hInstance=0x400000, nCmdShow=10)
    at ../../src/msw/main.cpp:415
#17 0x004015a7 in WinMain@16 (hInstance=0x400000, hPrevInstance=0x0,
    nCmdShow=10) at controls.cpp:376
#18 0x007d3a6d in main ()
(gdb)

Attachments (1)

utilscmn.patch download (553 bytes) - added by ZaneUJi 13 months ago.
utilscmn.patch

Download all attachments as: .zip

Change History (6)

Changed 13 months ago by ZaneUJi

utilscmn.patch

comment:1 Changed 13 months ago by disc

  • Component changed from wxMSW to GUI-all
  • Status changed from new to confirmed

I see the problem and also that the fix solves it. I was wondering about something minor: is there a preference to use "break;" or "return out;" as a fix here?

comment:2 Changed 13 months ago by ericj

The "&" char is used to indicate keyboard shortcuts by underlining the *following* character. In your case there is no following character. If you want to display just "&", use "&&" in the string.

comment:3 Changed 13 months ago by vadz

@ericj, It's true that the string is invalid, hence a debug log message. But we still shouldn't crash, of course.

@disc: Frankly, I don't know. I'll just apply the patch as is, I don't see any problem with having a "break" here.

@ZaneUJi: Thanks for finding and fixing the bug!

comment:4 Changed 13 months ago by VZ

  • Resolution set to fixed
  • Status changed from confirmed to closed

(In [75179]) Fix crash when setting invalid label with "&" at the end.

We detected that the label was invalid and gave a debug warning message about
it but then still proceeded to crash by accessing the data beyond the end of
the string. Don't do this.

Closes #15665.

comment:5 Changed 13 months ago by VZ

(In [75180]) Fix crash when setting invalid label with "&" at the end.

We detected that the label was invalid and gave a debug warning message about
it but then still proceeded to crash by accessing the data beyond the end of
the string. Don't do this.

Closes #15665.

Note: See TracTickets for help on using tickets.