Commit 1b12fcca authored by jan.koester's avatar jan.koester
Browse files

search by id now use heap

parent 26d7e2e8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ enable_testing ()
set(LIBV "1.0.0")
set(Upstream_VERSION 1.0.0)

SET(CMAKE_CXX_FLAGS "-fPIC -Wall")
SET(CMAKE_CXX_FLAGS "-fPIC -Wall -fstack-check -fstack-protector")

configure_file(config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)

+12 −4
Original line number Diff line number Diff line
@@ -971,19 +971,27 @@ PRINTNEXTEL:
}

libhtmlpp::HtmlElement *libhtmlpp::HtmlElement::getElementbyID(const char *id) const{
    for(const Element *curel=this; curel; curel=curel->nextElement()){
    std::stack <Element*> *childs=new std::stack <Element*>;
    const Element *curel=this;
SEARCHBYID:
    while( (curel=curel->nextElement()) ) {
        if(curel->getType()==HtmlEl){
            if(((HtmlElement*)curel)->_childElement){
                HtmlElement *find=((HtmlElement*)((HtmlElement*)curel)->_childElement)->getElementbyID(id);
                if(find)
                    return find;
                childs->push(((HtmlElement*)curel)->_childElement);
            }
            const char *key=((HtmlElement*)curel)->getAtributte("id");
            if(key && strcmp(key,id)==0){
                delete childs;
                return (HtmlElement*)curel;
            }
        }
    }
    if(!childs->empty()){
        curel=childs->top();
        childs->pop();
        goto SEARCHBYID;
    }
    delete childs;
    return nullptr;
}