Merge lp:~gamag/widelands/bug1097420 into lp:widelands

Proposed by Gabriel Margiani
Status: Merged
Merged at revision: 6486
Proposed branch: lp:~gamag/widelands/bug1097420
Merge into: lp:widelands
Diff against target: 19 lines (+2/-7)
1 file modified
src/ui_basic/tabpanel.cc (+2/-7)
To merge this branch: bzr merge lp:~gamag/widelands/bug1097420
Reviewer Review Type Date Requested Status
Mark Scott Approve
Review via email: mp+142412@code.launchpad.net

Description of the change

The tabpanel gave a const char* to the set_tooltip, which needs a const std::string& .....

(This is a very small change, but maybe a review is good anyway :)

To post a comment you must log in.
Revision history for this message
Mark Scott (mxsscott) wrote :

Right fix, wrong reason.

set_tooltip(const std::string&) will take a "const char*" - the compiler implicitly constructs a 'string' from the 'const char*' by using the 'string::string(const char*)' constructor.

If the Tab's tooltip is the empty string "", then the line 't = str.c_str();' will not be executed, leaving 't' with the value 0.

The implicit string constructor will crash if passed a null pointer, giving us this:

   "The exception said: basic_string::_S_construct null not valid"

(std::string is usually a template instantiation of std::basic_string<char>)

review: Approve
Revision history for this message
SirVer (sirver) wrote :

stuff like this happen easy when you convert const char* to string - which i recently did for tooltips.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ui_basic/tabpanel.cc'
2--- src/ui_basic/tabpanel.cc 2012-12-14 20:09:35 +0000
3+++ src/ui_basic/tabpanel.cc 2013-01-08 22:07:27 +0000
4@@ -315,13 +315,8 @@
5
6 if (hl != m_highlight) {
7 {
8- const char * t = 0;
9- if (hl >= 0) {
10- const std::string & str = m_tabs[hl]->tooltip;
11- if (str.size())
12- t = str.c_str();
13- }
14- set_tooltip(t);
15+ if (hl >= 0)
16+ set_tooltip(m_tabs[hl]->tooltip);
17 }
18 if (m_highlight >= 0)
19 update

Subscribers

People subscribed via source and target branches

to status/vote changes: