Florian Quetting wrote:
Hello.
I wrote a litte program, that generates a SIGSEGV after a while.
parse_umfeld is my method. It runs through about 330 times without error,
but the next time, call to strlen (from within parse_umfeld) generates a
SIGSEGV.
The problem with things like that is, that the actual program crash
is only lousy connected with the real problem. In other words: you
see the symptoms, but not the cause. You can bet your ass, that
nothing is wrong with strlen, but with the pointer you feed
to it.
How could I find out, why exactly the problem occures?
gdb bt gives:
Program received signal SIGSEGV, Segmentation fault.
0xb7e30173 in strlen () from /lib/tls/i686/cmov/libc.so.6
(gdb) bt
#0 0xb7e30173 in strlen () from /lib/tls/i686/cmov/libc.so.6
#1 0x0804a20a in c_Parser::parse_umfeld (this=0x8050050,
buffer=0x8053c8b
"<Feld><Boden>Rasen</Boden><Ameise><Typ>Rot</Typ><ID>1</ID><Blickrichtung>NO</Blickrichtung><Angegriffen>0</Angegriffen></Ameise></Feld><Feld><Boden>Rasen</Boden></Feld><Feld><Boden>Rasen</Boden></Feld"...)
at c_Parser.cpp:69
<snip>
What does entry #0 mean?
Forget it.
Concentrate on the string you feed to strlen().
It obviously is not '\0' terminated. The question is: Why?
You need to start with that problem. Eg. you could:
for testing purposes assume that this string is never longer
then eg. 1024 characters. You then could write your own
version of strlen, which checks for that and alert you.
Things like that are hard to diagnose. This is why professionals
recommend a different way of development: development in small
steps. Only add small code sections at a time and test them until
you are very certain that they work ok. If you discover a bug you
can be very sure that it is somehow related to the last additions
you made. Since the last additions are relatively small (remember:
small steps), it is far easier to find the problem.
Also: Why are you using C-style strings instead of std::string ?
Also: You are aware that there are working XML readers available
for free?
--
Karl Heinz Buchegger
kb******@gascad.at