540 // draw numbers
541 std::ostringstream str;
542 str << i;
543 const char *num = str.str().c_str();
The str.str() is returning a temporary string, that gets immediately
freed, taking the returned c_str() with it. Bad. :)
Breakpoint 2, HUD::Ladder::draw (this=0xe235df0) at
src/Instrumentation/HUD/HUD_ladder.cxx:543
543 const char *num = str.str().c_str();
(gdb) x/8i $rip
0x869126 <_ZN3HUD6Ladder4drawEv+6840>: lea -0xc0(%rbp),%rdi
0x86912d <_ZN3HUD6Ladder4drawEv+6847>: lea -0x310(%rbp),%rsi
0x869134 <_ZN3HUD6Ladder4drawEv+6854>: callq 0x422cc8
<_znkst19basic_ostringstreamicst11char_traitsicesaicee3st...@plt>
0x869139 <_ZN3HUD6Ladder4drawEv+6859>: lea -0xc0(%rbp),%rdi
0x869140 <_ZN3HUD6Ladder4drawEv+6866>: callq 0x424528 <_znkss5c_st...@plt>
0x869145 <_ZN3HUD6Ladder4drawEv+6871>: mov %rax,-0x28(%rbp)
0x869149 <_ZN3HUD6Ladder4drawEv+6875>: lea -0xc0(%rbp),%rdi
0x869150 <_ZN3HUD6Ladder4drawEv+6882>: callq 0x4247a8 <_znssd...@plt>
--
Csaba/Jester
Index: src/Instrumentation/HUD/HUD_ladder.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/HUD/HUD_ladder.cxx,v
retrieving revision 1.30
diff -u -r1.30 HUD_ladder.cxx
--- src/Instrumentation/HUD/HUD_ladder.cxx 30 Jul 2008 15:01:59 -0000 1.30
+++ src/Instrumentation/HUD/HUD_ladder.cxx 14 Jan 2009 02:49:11 -0000
@@ -540,7 +540,9 @@
// draw numbers
std::ostringstream str;
str << i;
- const char *num = str.str().c_str();
+ // must keep this string, otherwise it will free the c_str!
+ string num_str = str.str();
+ const char *num = num_str.c_str();
int valign = numoffs.y > 0 ? BOTTOM : numoffs.y < 0 ? TOP : VCENTER;
draw_text(lo.x - numoffs.x, lo.y + numoffs.y, num,
valign | (numoffs.x == 0 ? CENTER : numoffs.x > 0 ? RIGHT : LEFT));
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/flightgear-devel