summaryrefslogtreecommitdiff
path: root/lib/backupstore
diff options
context:
space:
mode:
authorChris Wilson <chris+github@qwirx.com>2014-12-22 23:09:31 +0000
committerChris Wilson <chris+github@qwirx.com>2014-12-22 23:09:31 +0000
commit6622bfe4eb59a2f38f7012349525ec64f0368118 (patch)
treeb116a1ec4a429ad3ecf0d8817488557f196782b1 /lib/backupstore
parente88418c0145ddeba97116e49074dd8e2e9edea7a (diff)
Replace sprintf() with snprintf(), fixes compile warnings on OpenBSD.
And compile errors on recent MinGW.
Diffstat (limited to 'lib/backupstore')
-rw-r--r--lib/backupstore/BackupStoreAccountDatabase.cpp3
-rw-r--r--lib/backupstore/BackupStoreAccounts.cpp6
-rw-r--r--lib/backupstore/BackupStoreCheck.cpp3
-rw-r--r--lib/backupstore/BackupStoreCheck2.cpp4
-rw-r--r--lib/backupstore/BackupStoreContext.cpp2
-rw-r--r--lib/backupstore/BackupStoreFileDiff.cpp6
6 files changed, 14 insertions, 10 deletions
diff --git a/lib/backupstore/BackupStoreAccountDatabase.cpp b/lib/backupstore/BackupStoreAccountDatabase.cpp
index 201491a3..c5f012fc 100644
--- a/lib/backupstore/BackupStoreAccountDatabase.cpp
+++ b/lib/backupstore/BackupStoreAccountDatabase.cpp
@@ -247,7 +247,8 @@ void BackupStoreAccountDatabase::Write()
{
// Write out the entry
char line[256]; // more than enough for a couple of integers in string form
- int s = ::sprintf(line, "%x:%d\n", i->second.GetID(), i->second.GetDiscSet());
+ int s = ::snprintf(line, sizeof(line), "%x:%d\n",
+ i->second.GetID(), i->second.GetDiscSet());
if(::write(file, line, s) != s)
{
THROW_EXCEPTION(CommonException, OSFileError)
diff --git a/lib/backupstore/BackupStoreAccounts.cpp b/lib/backupstore/BackupStoreAccounts.cpp
index 22628017..7bfa029d 100644
--- a/lib/backupstore/BackupStoreAccounts.cpp
+++ b/lib/backupstore/BackupStoreAccounts.cpp
@@ -158,9 +158,9 @@ void BackupStoreAccounts::GetAccountRoot(int32_t ID, std::string &rRootDirOut, i
std::string BackupStoreAccounts::MakeAccountRootDir(int32_t ID, int DiscSet)
{
char accid[64]; // big enough!
- ::sprintf(accid, "%08x" DIRECTORY_SEPARATOR, ID);
- return std::string(std::string(BOX_RAIDFILE_ROOT_BBSTORED
- DIRECTORY_SEPARATOR) + accid);
+ ::snprintf(accid, sizeof(accid) - 1, "%08x" DIRECTORY_SEPARATOR, ID);
+ return std::string(BOX_RAIDFILE_ROOT_BBSTORED DIRECTORY_SEPARATOR) +
+ accid;
}
diff --git a/lib/backupstore/BackupStoreCheck.cpp b/lib/backupstore/BackupStoreCheck.cpp
index 33660ffc..5f1b90d1 100644
--- a/lib/backupstore/BackupStoreCheck.cpp
+++ b/lib/backupstore/BackupStoreCheck.cpp
@@ -474,7 +474,8 @@ void BackupStoreCheck::CheckObjectsDir(int64_t StartID)
{
// Check the object is OK, and add entry
char leaf[8];
- ::sprintf(leaf, DIRECTORY_SEPARATOR "o%02x", i);
+ ::snprintf(leaf, sizeof(leaf),
+ DIRECTORY_SEPARATOR "o%02x", i);
if(!CheckAndAddObject(StartID | i, dirName + leaf))
{
// File was bad, delete it
diff --git a/lib/backupstore/BackupStoreCheck2.cpp b/lib/backupstore/BackupStoreCheck2.cpp
index e5728fa9..13831a09 100644
--- a/lib/backupstore/BackupStoreCheck2.cpp
+++ b/lib/backupstore/BackupStoreCheck2.cpp
@@ -356,7 +356,7 @@ void BackupStoreDirectoryFixer::InsertObject(int64_t ObjectID, bool IsDirectory,
{
// Directory -- simply generate a name for it.
char name[32];
- ::sprintf(name, "dir%08x", lostDirNameSerial);
+ ::snprintf(name, sizeof(name), "dir%08x", lostDirNameSerial);
objectStoreFilename.SetAsClearFilename(name);
}
else
@@ -447,7 +447,7 @@ int64_t BackupStoreCheck::GetLostAndFoundDirID()
while(true)
{
char name[32];
- ::sprintf(name, "lost+found%d", n++);
+ ::snprintf(name, sizeof(name), "lost+found%d", n++);
lostAndFound.SetAsClearFilename(name);
if(!dir.NameInUse(lostAndFound))
{
diff --git a/lib/backupstore/BackupStoreContext.cpp b/lib/backupstore/BackupStoreContext.cpp
index 3769344b..22239532 100644
--- a/lib/backupstore/BackupStoreContext.cpp
+++ b/lib/backupstore/BackupStoreContext.cpp
@@ -165,7 +165,7 @@ bool BackupStoreContext::AttemptToGetWriteLock()
{
// The housekeeping process might have the thing open -- ask it to stop
char msg[256];
- int msgLen = sprintf(msg, "r%x\n", mClientID);
+ int msgLen = snprintf(msg, sizeof(msg), "r%x\n", mClientID);
// Send message
mpHousekeeping->SendMessageToHousekeepingProcess(msg, msgLen);
diff --git a/lib/backupstore/BackupStoreFileDiff.cpp b/lib/backupstore/BackupStoreFileDiff.cpp
index fd186e7c..1d83d854 100644
--- a/lib/backupstore/BackupStoreFileDiff.cpp
+++ b/lib/backupstore/BackupStoreFileDiff.cpp
@@ -1042,9 +1042,11 @@ static void GenerateRecipe(BackupStoreFileEncodeStream::Recipe &rRecipe, BlocksA
{
char b[64];
#ifdef WIN32
- sprintf(b, "%8I64d", (int64_t)(rRecipe[e].mpStartBlock - pIndex));
+ snprintf(b, sizeof(b), "%8I64d", (int64_t)
+ (rRecipe[e].mpStartBlock - pIndex));
#else
- sprintf(b, "%8lld", (int64_t)(rRecipe[e].mpStartBlock - pIndex));
+ snprintf(b, sizeof(b), "%8lld", (int64_t)
+ (rRecipe[e].mpStartBlock - pIndex));
#endif
BOX_TRACE(std::setw(8) <<
rRecipe[e].mSpaceBefore <<