Skip to content

Commit

Permalink
replace deprecated sprintf with snprintf
Browse files Browse the repository at this point in the history
  • Loading branch information
carltimmer committed Sep 18, 2024
1 parent 92e1f81 commit 5ca68d8
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/libsrc++/Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ namespace evio {
// then tack stream id and split # onto end of file name
else if (specifierCount == 1) {
char tempChar[fileName.length() + 1024];
int err = std::sprintf(tempChar, fileName.c_str(), runNumber);
int err = std::snprintf(tempChar, fileName.length() + 1024, fileName.c_str(), runNumber);
if (err < 0) throw EvioException("badly formatted file name");
std::string temp(tempChar);
fileName = temp;
Expand Down Expand Up @@ -1267,14 +1267,14 @@ namespace evio {
//fileName.replace(match[0].first, match[0].second, "%d." + match.str());

char tempChar[fileName.length() + 1024];
int err = std::sprintf(tempChar, fileName.c_str(), runNumber, streamId, splitNumber);
int err = std::snprintf(tempChar, fileName.length() + 1024, fileName.c_str(), runNumber, streamId, splitNumber);
if (err < 0) throw EvioException("badly formatted file name");
std::string temp(tempChar);
fileName = temp;
}
else {
char tempChar[fileName.length() + 1024];
int err = std::sprintf(tempChar, fileName.c_str(), runNumber, splitNumber);
int err = std::snprintf(tempChar, fileName.length() + 1024, fileName.c_str(), runNumber, splitNumber);
if (err < 0) throw EvioException("badly formatted file name");
std::string temp(tempChar);
fileName = temp;
Expand All @@ -1283,7 +1283,7 @@ namespace evio {
// For 3 specifiers: insert run #, stream id, and split # at specified locations
else if (specifierCount == 3) {
char tempChar[fileName.length() + 1024];
int err = std::sprintf(tempChar, fileName.c_str(), runNumber, streamId, splitNumber);
int err = std::snprintf(tempChar, fileName.length() + 1024, fileName.c_str(), runNumber, streamId, splitNumber);
if (err < 0) throw EvioException("badly formatted file name");
std::string temp(tempChar);
fileName = temp;
Expand All @@ -1302,7 +1302,7 @@ namespace evio {
else if (specifierCount == 1) {
// Insert runNumber
char tempChar[fileName.length() + 1024];
int err = std::sprintf(tempChar, fileName.c_str(), runNumber);
int err = std::snprintf(tempChar, fileName.length() + 1024, fileName.c_str(), runNumber);
if (err < 0) throw EvioException("badly formatted file name");
std::string temp(tempChar);
fileName = temp;
Expand All @@ -1326,7 +1326,7 @@ namespace evio {

// Insert runNumber into first specifier
char tempChar[fileName.length() + 1024];
int err = std::sprintf(tempChar, fileName.c_str(), runNumber);
int err = std::snprintf(tempChar, fileName.length() + 1024, fileName.c_str(), runNumber);
if (err < 0) throw EvioException("badly formatted file name");
std::string temp(tempChar);
fileName = temp;
Expand All @@ -1350,7 +1350,7 @@ namespace evio {

// Insert runNumber into first specifier, stream id into 2nd
char tempChar[fileName.length() + 1024];
int err = std::sprintf(tempChar, fileName.c_str(), runNumber, streamId);
int err = std::snprintf(tempChar, fileName.length() + 1024, fileName.c_str(), runNumber, streamId);
if (err < 0) throw EvioException("badly formatted file name");
std::string temp(tempChar);
fileName = temp;
Expand Down

0 comments on commit 5ca68d8

Please sign in to comment.