Skip to content

Commit 0ae04a6

Browse files
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.
1 parent adb7e7c commit 0ae04a6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/Database.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ Header Database::getHeaderInfo(const std::string& aFilename)
310310
}
311311

312312
// If the "magic string" can't be found then header is invalid, corrupt or unreadable
313-
strncpy(pHeaderStr, pBuf, 16);
313+
memcpy(pHeaderStr, pBuf, 16);
314+
pHeaderStr[15] = '\0';
314315
if (strncmp(pHeaderStr, "SQLite format 3", 15) != 0)
315316
{
316317
throw SQLite::Exception("Invalid or encrypted SQLite header in file " + aFilename);

0 commit comments

Comments
 (0)