Archiv verlassen und diese Seite im Standarddesign anzeigen : Segmentation fault
Will eine kleine cgi lib geschrieben, bekomme aber wenn ich sie aufrufe einen fehler zurück:
index.cgi output
./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
#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", "Forminput Forminput1 Forminput2", "GET");
cout << "<body>" << endl
<< "<h1><em>" << endl
<< "Im Aufbau" << endl
<< "</em></h1>" << endl
<< "</body>" << endl
<< "</html>"<< endl;
}
libhtml++.h
#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
#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
{
}
}
anda_skoa
25-02-2007, 18:11
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,
_
Habe dies jetz geändert das resultat bleibt leider gleich
#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:
#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("");
if(pos != string::npos)
formselectinputprint.replace(pos,strlen(""),"<option>");
}
while(pos != string::npos);
do
{
pos = formselectinputprint.find("");
if(pos != string::npos)
formselectinputprint.replace(pos,strlen(""),"</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
anda_skoa
26-02-2007, 00:10
Probier es mal eher so
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,
_
Habe jetzt den Konstruktor rausgenommen cgi.cpp in die klasse anfrage gesteckt jetzt kommt
gcc output:
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
#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
#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("");
if(pos != string::npos)
formselectinputprint.replace(pos,strlen(""),"<option>");
}
while(pos != string::npos);
do
{
pos = formselectinputprint.find("");
if(pos != string::npos)
formselectinputprint.replace(pos,strlen(""),"</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);
}
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
#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", "Forminput Forminput1 Forminput2", "GET");
cout << "<body>" << endl
<< "<h1><em>" << endl
<< "Im Aufbau" << endl
<< "</em></h1>" << endl
<< "</body>" << endl
<< "</html>"<< endl;
}
anda_skoa
26-02-2007, 20:20
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,
_
Ops Schuldigung :o hatte noch die alte cgi.cpp gepastet.
Aber wie kann ich eine Intanz ohne konstruktor erzeugen, da ich einen Rüchgabe wert habe ?
Daraus ist meines Erachtens der Fehler Entstanden
Habe den string static deklariert bekomme jetzt aber :
formselect.cpp:36: error: cannot declare member function ‘static std::string htmlformselect::formselect(std::string, std::string, std::string)’ to have static linkage
formselect.cpp: In static member function ‘static std::string htmlformselect::formselect(std::string, std::string, std::string)’:
formselect.cpp:38: error: cannot call member function ‘std::string cgi::anfrage(std::string)’ without object
formselect.cpp:39: error: cannot call member function ‘std::string htmlformselect::formselectdisplay(std::string, std::string, std::string)’ without object
make: *** [all] Error 1
, da der wie zu übergebenden werte nicht statisch sind.
anda_skoa
27-02-2007, 13:59
Aber wie kann ich eine Intanz ohne konstruktor erzeugen
Das ist nicht möglich. Du brauchst keinen eigenen Konstruktor, C++ generiert einen Defaultkonstruktor (Ohne Argument) wenn man selber keinen Konstruktor deklariert, aber ohne Konstruktor keine Instanz.
Also einfach eine Instanz anlegen und dann dessen Methode aufrufen.
Habe den string static deklariert bekomme jetzt aber :
Du hast die Implementierung als static markiert, das hat eine ganz andere Bedeutung :)
Aber besser du arbeitest mit einer Instanz, wie oben beschrieben.
Ciao,
_
Quasi so :
htmlformselect(std::string formselectname, std::string formselectinput, std::string methodform)
{
formselect(formselectname, formselectinput, methodform);
};
;-) compeliern geht aber das programm schmiert mir immer ab :)
gdb output:
Program received signal SIGSEGV, Segmentation fault.
0xb7d72de7 in free () from /lib/tls/i686/cmov/libc.so.6
Sourcecode liegt in:
ftp://tuxist.de/tuxist/tuxcms
anda_skoa
27-02-2007, 20:45
Quasi so :
htmlformselect(std::string formselectname, std::string formselectinput, std::string methodform)
{
formselect(formselectname, formselectinput, methodform);
};
Nein, quasi so:
// Objekt anlegen
htmlformselect helper:
// Objekt verwenden
helper.formselect("Formselect1", "Forminput Forminput1 Forminput2", "GET"):
gdb output:
Program received signal SIGSEGV, Segmentation fault.
0xb7d72de7 in free () from /lib/tls/i686/cmov/libc.so.6
Das hilft nicht weiter, du mußt einen Backtrace erzeugen (im gdb "bt" eingeben). Dann sieht man nämlich, woher der Aufruf kommt (den sogenannten Callstack)
Sourcecode liegt in:
ftp://tuxist.de/tuxist/tuxcms
Wie wäre es mit einem Archiv? tgz zum Beispiel?
Ciao,
_
backtrace
gdb) bt
#0 0xb7d47de7 in free () from /lib/tls/i686/cmov/libc.so.6
#1 0xb7f05cf1 in operator delete () from /usr/lib/libstdc++.so.6
#2 0xb7ee2a5d in std::string::_Rep::_M_destroy () from /usr/lib/libstdc++.so.6
#3 0xb7ee55e7 in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string () from /usr/lib/libstdc++.so.6
#4 0xb7f51f9d in htmlformselect::formselect ()
from /usr/lib/tuxcms/libhtml++.so
#5 0x0804901b in htmlformselect::htmlformselect ()
#6 0x08048c4a in main ()
Habe ein tar.gz achiv erstellt
ftp://tuxist.de/tuxist/tuxcms.tar.gz
anda_skoa
01-03-2007, 23:19
Das Problem ließ sich relativ leicht finden, man muß nur dem Compiler erlauben, einem ein bischen zu helfen :)
Wenn du in libhtml++ auch Warnings einschaltest, sagt er dir nämlich, daß zwei Methoden zwar einen Returnwert spezifizieren, aber keinen Wert zurück geben.
Ich rate auch dazu, während der Entwicklung das Hinzufügen von Debuginformationen zu erlauben, d.h. "-g" als Option in den Compilerflags.
Ciao,
_
Danke habe fehler gefunden ;-)
War selten dähmlich select ohne submit macht wenig sinn ;-)
Powered by vBulletin® Version 4.2.5 Copyright ©2025 Adduco Digital e.K. und vBulletin Solutions, Inc. Alle Rechte vorbehalten.