c++ - sql3_finalize creates a segfault -


I am trying to code a function that creates a zSQL database with the order of a file using SQLite is. The code for my function is as follows:

  bool createDatabaseFromFile (database & amp; db, std :: istream & commandfile, const char * dbName, std :: ostream * err, bool multiline queries) {Details stmt; Std :: string line STR; std :: string queryStr; Bool end = false; If (! DbName) // If the database address is not provided, then we get it from the first line of command file {std :: getline (commandFile, lineStr); dbName = lineStr.c_str (); } bool noError = db.open (dbName, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, mistake); // If the database does not open, the following loops are not used while (std :: getline (commandFile, lineStr) & amp; amp; amp; amp; amp; amp; amp; amp ; if (lineStr.substr (0,4) == "#END") until the end of the file or keyword "#END"; amp; amp; amp; amp; amp; amp; True; else if (lineStr.substr! (0,2)! = "//") // except the lines of commentary queryStr + = lineStr; if (! MultilineQueries) // If all the lines as a query query If so, then;} ;;;;;;;} std :: string :: size_type start_query = 0; std :: string :: size_type end_query; std :: string query; while (start_query! = std :: string :: npos & amp;; noError) // All queries of the string are executed until an issue or an error occurs {end_query = queryStr.find_first_of (';', start_query); query = queryStr.substr (start_query, end_query); if (db.prepare (query.c_str (), lineStr.size (), stmt)) / / If no error returns not returned sql3_prepare {noError = stmt.makeAllSteps (); } No more; Error = false; Start_query = end_query; If (start_query! = Std :: string :: npos) start_query ++; // other "cursors" live on the same; 'Over and over} returns noir; }   

STMAT class is basically a wrapper around sqlite3_stmt. When it is destroyed at the end of the code, it is called sqlite3_finalize, which is why I do not understand a segfault for a reason. What's the problem

The error call stack is:

  sqlite3_finalize (pstmt = 0x3) sql3 :: statement :: erase (this = 0x28f9e0) sql3:: statement :: ~ statement (This = 0x28f9e0, __in_chrg = & lt; optimize out & gt;) sql3 :: createDatabaseFromFile (db = ..., commandFile = ..., dbName = 0x51e057 "resins \\ DatabaseFile.txt", err = 0x533cc0, multilineQueries = true)   

Here is the code of the destroyer:

  zero sql3 :: statement :: deleted () {if (p_stmt) testcode (sqlite3_finalize (p_stmt) ), USING_INCORRECT_STATEMENT, nullptr, std :: cerr); // testcode is a consoleable function, so the above is equal to: if (p_stmt) sqlite3_finalize (p_stmt); P_stmt = nullptr; } Sql3 :: Description :: ~ Statement () {Erase (); Apart from this, not sure what that means, but if I call the statement :: (all) statement: makeAllSteps () then I have no error. EDIT: Apparently, it means that for some time the loop (start_query! Std :: string :: npos & amp;; noError) is skipped.  

EDIT 2: Found it, it is! No error. When I get permission, I will post an answer.

Dear people's future, here's what I happened so far:

There were two problems in my code. The first is this:

  while (start_query! = Std :: string :: npos & amp;; noError)   

which should be

  while (start_query! = std :: string :: npos & noError)   

(In the first one, noError starts to be true, which means that The loop has been abandoned)

The second, more common problem in my project, is the sql3 :: statement in the manufacturer: I forgot to include a line to set the sqlite3_stmt pointer to nullptr.

Actually, one segfault can be returned to finalize the call in a way, if the pointer was not initialized with either the npler or with the initial functions.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -