And of course, finalize after close is wrong.  You finalize the statement, then 
close the db, then bail.

---
()  ascii ribbon campaign against html e-mail
/\  www.asciiribbon.org


> -----Original Message-----
> From: sqlite-users-boun...@sqlite.org [mailto:sqlite-users-
> boun...@sqlite.org] On Behalf Of Robert Myers
> Sent: Monday, 23 July, 2012 21:44
> To: sqlite-users@sqlite.org
> Subject: Re: [sqlite] C++ - Creating Table
> 
> On 7/23/2012 7:43 PM, Arbol One wrote:
> > Thank you Michael for your prompt response.
> > I have been able to duplicate the error message. I think this could be a
> bug
> > in SQLite3.
> > void jme::mySQLite3::createTable(const std::string& s) throw
> > (std::exception) {
> >      rc = sqlite3_prepare_v2( db, s.c_str(), -1, &stmt, NULL);
> >      if(rc != SQLITE_OK) {
> rc is a bool, not an int, you have a type coercion error here.
> 
> >          sqlite3_close(db);
> >          sqlite3_finalize(stmt);
> >          std::string error("Error prepare_v2: ");
> >          error += sqlite3_errmsg(db);
> >          std::cout << "Error: " << rc << " " << error << std::endl;
> >      }
> >      rc = sqlite3_step(stmt);
> There's a use after free error here  (you don't return / throw after
> finalizing)
> >      std::cout << "Error: " << rc << std::endl;
> >
> >      if(rc != SQLITE_DONE) {
> And another type coercion error here. rc will never be equal to SQLITE_DONE.
> 
> >          sqlite3_close(db);
> >          sqlite3_finalize(stmt);
> And another use after free here, since the step will fail, you'll close
> it again. Of course, that assumes the step isn't going to crash in the
> first place.
> >          std::string error("error sqlite3_step: ");
> >          error += sqlite3_errmsg(db);
> >          std::cout << error << std::endl;
> >      }
> >      sqlite3_finalize(stmt);
> 
> And another use after free here, same problem with the error handling.
> 
> You're committing one of the cardinal sins of C++. Let the compiler do
> all the work, don't do it yourself, you'll (generic you) screw it up.
> Wrap the DB and query in objects that handle the clean up for you.
> 
> Compile everything (except sqlite3.c itself) at the highest possible
> warning level treating warnings as errors. That would've caught the type
> error. It's one of the first things I set up with new projects.
> 
> Rob
> 
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users



_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to