reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit d1b7958963fb6348a6e86538110c69deb0e52121
parent cd0766d82fb96eb54d2761cfcac9114275536b73
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Sun, 14 Feb 2016 03:54:50 -0500

don't crash when accessing an invalid sqlite text column

Diffstat:
Msrc/database.cpp | 7++++++-
Mtest/database.cpp | 15+++++++++++++++
2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/src/database.cpp b/src/database.cpp @@ -169,5 +169,10 @@ uint64_t Statement::uint64Column(const int index) const string Statement::stringColumn(const int index) const { - return (char *)sqlite3_column_text(m_stmt, index); + char *col = (char *)sqlite3_column_text(m_stmt, index); + + if(col) + return col; + else + return {}; } diff --git a/test/database.cpp b/test/database.cpp @@ -175,3 +175,18 @@ TEST_CASE("sqlite error code", M) { REQUIRE(db.errorCode() == SQLITE_CONSTRAINT_UNIQUE); } + +TEST_CASE("invalid string column", M) { + Database db; + db.exec("CREATE TABLE a(text TEXT NOT NULL)"); + + Statement *insert = db.prepare("INSERT INTO a VALUES(?)"); + insert->bind(1, "hello"); + insert->exec(); + + Statement *select = db.prepare("SELECT text FROM a LIMIT 1"); + select->exec([&] { + REQUIRE(select->stringColumn(4242).empty()); // don't crash! + return false; + }); +}