Skip to content

Commit

Permalink
Replace sprintf with snprintf
Browse files Browse the repository at this point in the history
  • Loading branch information
milot-mirdita committed Apr 11, 2023
1 parent 91b8452 commit 3626bdb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/commons/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ class Debug
}
char fmtbuffer[32];
if(exp < 3){
int fmtElm = sprintf(fmtbuffer, "%d", static_cast<int>(id+1));
int fmtElm = snprintf(fmtbuffer, sizeof(fmtbuffer), "%d", static_cast<int>(id+1));
line.append(fmtbuffer, fmtElm);
}else{
int fmtElm = sprintf(fmtbuffer, "%.2f", static_cast<float>(id+1)/ static_cast<float>(base));
int fmtElm = snprintf(fmtbuffer, sizeof(fmtbuffer), "%.2f", static_cast<float>(id+1)/ static_cast<float>(base));
line.append(fmtbuffer, fmtElm);
line.push_back(appending);
}
Expand Down Expand Up @@ -244,7 +244,7 @@ class Debug
}
}
char buffer[32];
int n = sprintf(buffer, "%.2f", progress * 100.0f);
int n = snprintf(buffer, sizeof(buffer), "%.2f", progress * 100.0f);
line.append("] ");
line.append(buffer, n);
line.append("% ");
Expand Down
4 changes: 2 additions & 2 deletions src/commons/Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -654,13 +654,13 @@ std::string SSTR(unsigned long long x) {
template<>
std::string SSTR(double x) {
char buffer[32];
int n = sprintf(buffer, "%.3E", x);
int n = snprintf(buffer, sizeof(buffer), "%.3E", x);
return std::string(buffer, n);
}

template<>
std::string SSTR(float x) {
char buffer[32];
int n = sprintf(buffer, "%.3f", x);
int n = snprintf(buffer, sizeof(buffer), "%.3f", x);
return std::string(buffer, n);
}
2 changes: 1 addition & 1 deletion src/multihit/besthitperset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public :
for (size_t i = 0; i < bestEntry->size(); ++i) {
if (i == 1) {
char tmpBuf[15];
sprintf(tmpBuf, "%.3E", logCorrectedPval);
snprintf(tmpBuf, sizeof(tmpBuf), "%.3E", logCorrectedPval);
buffer.append(tmpBuf);
} else {
buffer.append(bestEntry->at(i));
Expand Down

0 comments on commit 3626bdb

Please sign in to comment.