Skip to content

Commit

Permalink
Replace sprintf with snprintf due to macOS deprecation
Browse files Browse the repository at this point in the history
sprintf is deprecated due to security concerns.
Using snprintf(3) instead to avoid warnings (-Wdeprecated-declarations).

Signed-off-by: Björn Svensson <[email protected]>
  • Loading branch information
bjosv committed Dec 5, 2024
1 parent 45127b4 commit c38228f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
3 changes: 1 addition & 2 deletions src/lib/data_mgr/ByteString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,7 @@ std::string ByteString::hex_str() const

for (size_t i = 0; i < byteString.size(); i++)
{
sprintf(hex, "%02X", byteString[i]);

snprintf(hex, sizeof(hex), "%02X", byteString[i]);
rv += hex;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/handle_mgr/test/handlemgrtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class MyProgressListener : public CppUnit::TextTestProgressListener
private:
std::string TimeFormat(double time) {
char buffer[320];
::sprintf(buffer, "%6f", time);
snprintf(buffer, sizeof(buffer), "%6f", time);
return buffer;
}

Expand Down
8 changes: 4 additions & 4 deletions src/lib/object_store/UUID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ std::string UUID::newUUID()

// Convert it to a string
char uuidStr[37];

sprintf(uuidStr, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
uuid[0], uuid[1], uuid[2], uuid[3],
uuid[4], uuid[5],
snprintf(uuidStr, sizeof(uuidStr),
"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
uuid[0], uuid[1], uuid[2], uuid[3],
uuid[4], uuid[5],
uuid[6], uuid[7],
uuid[8], uuid[9],
uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15]);
Expand Down

0 comments on commit c38228f

Please sign in to comment.