Seg fault in gdb only?


#1

Do you know something more on the subject.
OS: windows 2000
CC: gcc 3.4.2 (mingw)

This is the gdb output:

Breakpoint 1, main (argc=1, argv=0xaf24f8) at parse.cpp:67
67     if (option->isTextElement ()) {
(gdb) 
70     else if (option->hasTagName (T("code"))) {
(gdb) 
72         foreach (*option, str) {
(gdb) 
73             if (str->isTextElement ()) {
(gdb) 
74                 String s = str->getText ();
(gdb) 
75                 option->deleteAllTextElements ();
(gdb) 
76                 if (prefix.contains (s)) {
(gdb) 
80                     if (! fix.contains (s))
(gdb) 
81                         s = T("-") + s;
(gdb) 
83                 option->addTextElement (s);
(gdb) 
84                 fp (s);
(gdb) 
72         foreach (*option, str) {
(gdb) 
73             if (str->isTextElement ()) {
(gdb) 

Program received signal SIGSEGV, Segmentation fault.
0x00419dc9 in juce::XmlElement::isTextElement() const ()
(gdb) 
Single stepping until exit from function _ZNK4juce10XmlElement13isTextElementEv, 
which has no line number information.
gdb: unknown target exception 0xc00000cc at 0x00419dc9

Program received signal ?, Unknown signal.
0x00419dc9 in juce::XmlElement::isTextElement() const ()
(gdb) 
Single stepping until exit from function _ZNK4juce10XmlElement13isTextElementEv, 
which has no line number information.

JUCE: 1.39

As you can see from above it happened while working with XmlElement (isTextElement).

Also I had problems using this coding style:

 else if (option->hasTagName (T("code"))) {
    //XmlElement* str = option->getNextElement ();
    foreach (*option, str) {
       if (str->isTextElement ()) {

Using commented line resulted in seg fault (normal usage - not gdb only) and I had to use foreach (foreachxmlchildelement) …

Please comment.
Thanks…


#2

“foreach”? Eh? That’s not one of mine…

Maybe using forEachXmlChildElement might work better…?


#3

Well maybe is better to explain what the code is supposed to do:

  1. Lopp tags
  2. Find tag
  3. Modify its text element

And this is what my code does:

  1. Loop tags
  2. If found
  3. Loop text elements and for each element: get text / delete parents element () text elements / add modified text to parent element ()
foreach (*item, option) {
    if (option->isTextElement ()) {
        fp (option->getText ());
    }
    else if (option->hasTagName (T("code"))) {
        //XmlElement* str = option->getNextElement ();
        foreach (*option, str) {
            if (str->isTextElement ()) {
                String s = str->getText ();
                option->deleteAllTextElements ();
                if (prefix.contains (s)) {
                    s = T("--") + s;
                }
                else {
                    if (! fix.contains (s))
                        s = T("-") + s;
                }
                option->addTextElement (s);
                fp (s);
            }
        }
    }
    else
        fp (T("error: tag name: ") + option->getTagName ());
}

That’s it


#4

Sorry but I was using

#define foreach forEachXmlChildElement


#5

But you’re modifying the elements that you’re iterating - that’s a bit like sawing off the branch that you’re sitting on…


#6

Thanks I modified the code and it’s ok now.

Maybe a request is possible:

There is already XmlElement::getText(), why not add
XmlElement::setText(String text) or similar…


#7

yes, that’s a good request. Thanks.


#8