Anzeige:
Ergebnis 1 bis 14 von 14

Thema: Segmentation fault

Hybrid-Darstellung

Vorheriger Beitrag Vorheriger Beitrag   Nächster Beitrag Nächster Beitrag
  1. #1
    Registrierter Benutzer
    Registriert seit
    06.06.2004
    Beiträge
    76

    Segmentation fault

    Will eine kleine cgi lib geschrieben, bekomme aber wenn ich sie aufrufe einen fehler zurück:

    index.cgi output
    Code:
    ./index.cgi
    Content-Type:text/html
    
    
    <html>
    <head>
    <title></title>
    </head>
    <select name="Formselect1"<option>Forminput</option> <option>Forminput1</option> <option>Forminput2</option>method="GET"action="./cgi-bin/index.cgi">
    Segmentation fault
    index.cpp
    Code:
    #include <iostream>
    #include "index.h"
    #include <dlfcn.h>
    #include <tuxcms/css.h>
    #include <tuxcms/libhtml++.h>
    #include <string>
    
    using namespace std;
    
    int main(int argc, char **argv)
    {
    string sitename;
    cout << "Content-Type:text/html\n\n" << endl
         << "<html>" << endl
         << "<head>" << endl
         << "<title>" << sitename << "</title>" << endl
         << "</head>" << endl;
    htmlformselect::htmlformselect("Formselect1", "[F]Forminput[/F] [F]Forminput1[/F] [F]Forminput2[/F]", "GET");
    cout << "<body>" << endl
         << "<h1><em>" << endl
         << "Im Aufbau" << endl
         << "</em></h1>" << endl
         << "</body>" << endl
         << "</html>"<< endl;
    }
    libhtml++.h
    Code:
    #include <iostream>
    #include <string>
    #include <sstream>
    
    class htmlformselect 
    {
    private:
    std::string formselectinputprint;
    std::string formselectname;
    std::string formselectinput;
    std::string methodform;
    void formselectdisplay(std::string formselectname, std::string formselectinput, std::string methodform);
    std::string anfrage(std::string methodform);
    
    public:
    std::string formselectoutput;
    htmlformselect(std::string formselectname, std::string formselectinput, std::string methodform)
    {
    formselectdisplay(formselectname, formselectinput, methodform );
    anfrage(methodform);
    //std::cout << formselectoutput << std::endl; 
    } 
    
    
    };
    cgi.cpp
    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <cstdlib>
    #include "include/libhtml++.h"
    
    using namespace std;
    
    std::string htmlformselect::anfrage(std::string methodform )
    {
    if (methodform == "GET")
    {
    formselectoutput = getenv("QUERY_STRING");
    return formselectoutput;
    }
    
    else if (methodform =="POST")
    {
    return formselectoutput;
    }
    
    else
    {
    
    }
    
    }
    Hoddel aus Überzeugung

  2. #2
    Administrator Avatar von anda_skoa
    Registriert seit
    17.11.2001
    Ort
    Graz, Österreich
    Beiträge
    5.477
    Das sieht so aus, als hättest du den Rückgabewert von getenv() nicht überprüft.

    Soweit ich mich erinnern kann, wurdest du schon bei einem deinere anderen Threads darauf hingewiesen.

    Edit: hier http://www.mrunix.de/forums/showthread.php?t=49377

    Ciao,
    _
    Qt/KDE Entwickler
    Debian Benutzer

  3. #3
    Registrierter Benutzer
    Registriert seit
    06.06.2004
    Beiträge
    76
    Habe dies jetz geändert das resultat bleibt leider gleich
    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <cstdlib>
    #include "include/libhtml++.h"
    
    using namespace std;
    
    std::string htmlformselect::anfrage(std::string methodform )
    {
    
    char* buffer = 0; 
    unsigned int len;
    
    if (methodform == "GET")
    {
    len = strlen(getenv("QUERY_STRING")); 
         buffer = new char[len+1]; 
         strcpy(buffer,getenv("QUERY_STRING"));
    }
    
    else if (methodform =="POST")
    {
     len = atoi(getenv("CONTENT_LENGTH")); 
         buffer = new char[len+1]; 
         for(unsigned int i=0; i<len; i++) 
         cin.get(buffer[i]);
    }
    
    buffer[len] = 0;
    
    formselectoutput = buffer;
    delete[] buffer;
    return formselectoutput;
    }
    Vielleicht liegt es ja an dieser funktion:
    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <stdio.h>
    #include <cstdlib>
    #include "include/libhtml++.h"
    
    using namespace std;
    
    
    void htmlformselect::formselectdisplay (std::string formselectname, std::string formselectinput, std::string methodform)
    {
    
    formselectinputprint = formselectinput;
    
         int pos = 0;
         do
         {
              pos = formselectinputprint.find("[F]");
              if(pos != string::npos)
                    formselectinputprint.replace(pos,strlen("[F]"),"<option>");
         }
         while(pos != string::npos);
    
         do
         {
              pos = formselectinputprint.find("[/F]");
              if(pos != string::npos)
                    formselectinputprint.replace(pos,strlen("[/F]"),"</option>");
         }
         while(pos != string::npos);
    
    cout << "<select name=" << '"' << formselectname << '"' << formselectinputprint << "method=" << '"' << methodform << '"' << "action=" << '"' << "http://tuxist.de/cgi-bin/index.cgi" << '"' << ">" << endl;
    }
    link zur kompletten Anwendung:
    ftp://tuxist.de/tuxist/tuxcms
    Geändert von Tuxist (25-02-2007 um 18:54 Uhr)
    Hoddel aus Überzeugung

  4. #4
    Administrator Avatar von anda_skoa
    Registriert seit
    17.11.2001
    Ort
    Graz, Österreich
    Beiträge
    5.477
    Probier es mal eher so

    Code:
    if (methodform == "GET")
    {
        const char* query = getenv("QUERY_STRING");
        if (query != 0) formselectoutput = query;
    
        return formselectoutput;
    }
    Bzw, als allgemeine Hilfe:
    Mach in deinem Code an guten Stellen zusätzlich Output, nur nach eben nach "cerr", dann siehst du wie weiter das Programm kommt.

    Ciao,
    _
    Qt/KDE Entwickler
    Debian Benutzer

  5. #5
    Registrierter Benutzer
    Registriert seit
    06.06.2004
    Beiträge
    76
    Habe jetzt den Konstruktor rausgenommen cgi.cpp in die klasse anfrage gesteckt jetzt kommt

    gcc output:
    Code:
    ex.cpp:19: error: cannot call member function ‘std::string htmlformselect::formselect(std::string, std::string, std::string)’ without object
    make: *** [all] Error 1
    libhtml++.h
    Code:
    #include <iostream>
    #include <string>
    #include <sstream>
    
    class cgi
    {
    public:
    std::string anfrage(std::string methodform);
    std::string formselectoutput;
    std::string methodform;
    
    };
    
    class htmlformselect : public cgi
    {
    private:
    std::string formselectinputprint;
    std::string formselectname;
    std::string formselectinput;
    std::string formselectdisplay(std::string formselectname, std::string formselectinput, std::string methodform);
    public:
    
    std::string formselect(std::string formselectname, std::string formselectinput, std::string methodform);
    
    
    };
    formselect.cpp
    Code:
    #include <iostream>
    #include <string>
    #include <fstream>
    #include <stdio.h>
    #include <cstdlib>
    #include "include/libhtml++.h"
    
    using namespace std;
    
    
    string htmlformselect::formselectdisplay (std::string formselectname, std::string formselectinput, std::string methodform)
    {
    
    formselectinputprint = formselectinput;
    
         int pos = 0;
         do
         {
              pos = formselectinputprint.find("[F]");
              if(pos != string::npos)
                    formselectinputprint.replace(pos,strlen("[F]"),"<option>");
         }
         while(pos != string::npos);
    
         do
         {
              pos = formselectinputprint.find("[/F]");
              if(pos != string::npos)
                    formselectinputprint.replace(pos,strlen("[/F]"),"</option>");
         }
         while(pos != string::npos);
    
    cout << "<select name=" << '"' << formselectname << '"' << formselectinputprint << "method=" << '"' << methodform << '"' << "action=" << '"' << "http://tuxist.de/cgi-bin/index.cgi" << '"' << ">" << endl;
    }
    
    string htmlformselect::formselect (std::string formselectname, std::string formselectinput, std::string methodform)
    {
    anfrage(methodform);
    formselectdisplay(formselectname, formselectinput, methodform);
    }
    Code:
    std::string cgi::anfrage(std::string methodform )
    {
    char* buffer = 0; 
    unsigned int len;
    
    if (methodform == "GET")
    {
    len = strlen(getenv("QUERY_STRING")); 
         buffer = new char[len+1]; 
         strcpy(buffer,getenv("QUERY_STRING"));
    }
    
    else if (methodform =="POST")
    {
     len = atoi(getenv("CONTENT_LENGTH")); 
         buffer = new char[len+1]; 
         for(unsigned int i=0; i<len; i++) 
         cin.get(buffer[i]);
    }
    
    buffer[len] = 0;
    
    formselectoutput = buffer;
    delete[] buffer;
    return formselectoutput;
    }
    index.cpp
    Code:
    #include <iostream>
    #include "index.h"
    #include <dlfcn.h>
    #include <tuxcms/css.h>
    #include <tuxcms/libhtml++.h>
    #include <string>
    
    using namespace std;
    
    int main(int argc, char **argv)
    {
    string sitename;
    sitename = "tuxist.de";
    cout << "Content-Type:text/html\n\n" << endl
         << "<html>" << endl
         << "<head>" << endl
         << "<title>" << sitename << "</title>" << endl
         << "</head>" << endl;
    htmlformselect::formselect("Formselect1", "[F]Forminput[/F] [F]Forminput1[/F] [F]Forminput2[/F]", "GET");
    cout << "<body>" << endl
         << "<h1><em>" << endl
         << "Im Aufbau" << endl
         << "</em></h1>" << endl
         << "</body>" << endl
         << "</html>"<< endl;
    }
    Hoddel aus Überzeugung

  6. #6
    Administrator Avatar von anda_skoa
    Registriert seit
    17.11.2001
    Ort
    Graz, Österreich
    Beiträge
    5.477
    Das heitß, du hast weder eine Instanz der Klasse, noch ist die Methode statisch.

    Und der atoi() Aufruf (in C++ ohnehin eine "kleine Katastrophe" ) operiert möglicherweise auf einem Nullpointer, weiß nicht ob das erlaubt ist.

    Aber nachdem du ohnehin keine vorgeschlagene Änderung machst, sondern immer was anderes umbaust, frag ich mich langsam, ob es Sinn macht weiter zu antworten

    Ciao,
    _
    Qt/KDE Entwickler
    Debian Benutzer

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •