/gs-option verursacht das Programm zu werfen Ausnahme

Kurzem habe ich versucht, um ein kleines test-Programm, um die Kommunikation mit einem MySQL-server in C++. Ich bin derzeit mit MySQL Connector/C++ als meine API eine Verbindung zu meinem Datenbank-server. Es dauerte eine sehr lange Zeit, um es auszuführen, weil oracle/mysql hat wenig bis gar keine Dokumentation, wie Sie mithilfe von connector/c++ mit Visual Studio 10+.

Schließlich, nachdem alles funktioniert, scheint es einige Problem auf, wenn die Anwendung versucht, zu beenden. Es wirft die folgende nicht behandelte Ausnahme:

Unhandled exception at 0x00C62291 in mysql2.exe: Stack cookie instrumentation code detected a stack-based buffer overrun.

Nach der Suche über die Fehler, ich dachte, es war aufgrund der "Sicherheits-check" (option/gs-Compileroption). Wenn ich deaktivieren Sie diese compiler-option, beendet sich die Anwendung ordnungsgemäß.

Habe ich das Gefühl, dass ich es nicht ausschalten, da es die Standard-option in Visual Studio 2012 (und möglicherweise auch andere Versionen?)

Meine Fragen sind:

  • Warum ist diese /gs-Compileroption, wodurch die unbehandelte Ausnahme?
  • Ist es sicher okay oder zu deaktivieren, die /gs-Compileroption?

Hier ist das Stück code, das die nicht behandelte Ausnahme Punkte zu (innerhalb einer Datei, namens: gs_report.c):

#if defined (_M_IX86) || defined (_M_X64)
    if (IsProcessorFeaturePresent(PF_FASTFAIL_AVAILABLE))
#endif  /* defined (_M_IX86) || defined (_M_X64) */
    __fastfail(FAST_FAIL_STACK_COOKIE_CHECK_FAILURE);

Hier ist mein code für die Anwendung:

/* Standard C++ includes */
#include <stdlib.h>
#include <iostream>

/*
Include directly the different
headers from cppconn/and mysql_driver.h + mysql_util.h
(and mysql_connection.h). This will reduce your build time!
*/
#include "mysql_connection.h"
#include "mysql_driver.h"

#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>

using namespace std;

int main(void)
{
    cout << endl;
    cout << "Let's have MySQL count from 10 to 1..." << endl;

    try {
        sql::Driver *driver;
        sql::Connection *con;
        sql::Statement *stmt;
        sql::ResultSet *res;
        sql::PreparedStatement *pstmt;

        /* Create a connection */
        driver = sql::mysql::get_driver_instance();
        con = driver->connect("tcp://127.0.0.1:3306", "root", "MSxa5y");
        /* Connect to the MySQL test database */
        con->setSchema("test");

        stmt = con->createStatement();
        stmt->execute("DROP TABLE IF EXISTS test");
        stmt->execute("CREATE TABLE test(id INT)");
        delete stmt;

        /* '?' is the supported placeholder syntax */
        pstmt = con->prepareStatement("INSERT INTO test(id) VALUES (?)");
        for (int i = 1; i <= 10; i++) {
            pstmt->setInt(1, i);
            pstmt->executeUpdate();
        }
        delete pstmt;

        /* Select in ascending order */
        pstmt = con->prepareStatement("SELECT id FROM test ORDER BY id ASC");
        res = pstmt->executeQuery();

        /* Fetch in reverse = descending order! */
        res->afterLast();
        while (res->previous())
            cout << "\t... MySQL counts: " << res->getInt("id") << endl;
        delete res;

        delete pstmt;
        delete con;

    } catch (sql::SQLException &e) {
        cout << "# ERR: SQLException in " << __FILE__;
        cout << "() on line " << __LINE__ << endl;
        cout << "# ERR: " << e.what();
        cout << " (MySQL error code: " << e.getErrorCode();
        cout << ", SQLState: " << e.getSQLState() << " )" << endl;
    }

    cout << endl;

    return EXIT_SUCCESS;
}
InformationsquelleAutor TheAJ | 2012-12-16
Schreibe einen Kommentar