From 0ae04a60d965e8190d9ef4cf2245f7250cf04b72 Mon Sep 17 00:00:00 2001 From: Ben Stauffer Date: Mon, 9 Nov 2020 17:09:58 -0600 Subject: [PATCH] Fix build warning due to string truncation strncpy gives an "output may be truncated" warning in newer versions of GCC due to *pBuf being larger (100) than *pHeaderStr (16). Use memcpy and explicitly null-terminate the target string. --- src/Database.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Database.cpp b/src/Database.cpp index 059ab54..25c0b4b 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -310,7 +310,8 @@ Header Database::getHeaderInfo(const std::string& aFilename) } // If the "magic string" can't be found then header is invalid, corrupt or unreadable - strncpy(pHeaderStr, pBuf, 16); + memcpy(pHeaderStr, pBuf, 16); + pHeaderStr[15] = '\0'; if (strncmp(pHeaderStr, "SQLite format 3", 15) != 0) { throw SQLite::Exception("Invalid or encrypted SQLite header in file " + aFilename);