Skip to content

Commit

Permalink
Fix build warning due to string truncation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stauffer-garmin committed Nov 9, 2020
1 parent adb7e7c commit 0ae04a6
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0ae04a6

Please sign in to comment.