Noeud:The Third Bug, Noeud « Next »:Fun With Uninitialised Variables, Noeud « Previous »:Moving Around the Call Stack - Up+Down, Noeud « Up »:An example debugging session using gdb
Now we have changed char *buf;
to char buf[10];
. This will do for our example, but in 'real' code we should really use a safer mechanism such as using malloc
to allocate the right amount of space (including the terminating '\0'
, then using the safer strncpy()
to copy the string into it.
Let's run ecount3
and see what happens.
bash$ ecount3 example There are 1074045242 'e's in 'example'.
Can you spot what went wrong there? I only count 2 'e's in 'example'.
Lets fire up gdb
again and see where this number comes from.