Skip to content

Commit 5144d8e

Browse files
committed
fix sprintf warning
1 parent 5adae5b commit 5144d8e

File tree

1 file changed

+6
-7
lines changed
  • include/geometrycentral/utilities

1 file changed

+6
-7
lines changed

include/geometrycentral/utilities/timing.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ inline std::string pretty_time(long long microsec) {
3636
microsec -= hours * HOUR;
3737
long long minutes = microsec / MINUTE;
3838

39-
sprintf(buffer, "%lld hr, %lld min", hours, minutes);
39+
snprintf(buffer, sizeof(buffer), "%lld hr, %lld min", hours, minutes);
4040

4141
return std::string(buffer);
4242
}
@@ -47,7 +47,7 @@ inline std::string pretty_time(long long microsec) {
4747
microsec -= minutes * MINUTE;
4848
long long seconds = minutes / SECOND;
4949

50-
sprintf(buffer, "%lld min, %lld sec", minutes, seconds);
50+
snprintf(buffer, sizeof(buffer), "%lld min, %lld sec", minutes, seconds);
5151

5252
return std::string(buffer);
5353
}
@@ -56,7 +56,7 @@ inline std::string pretty_time(long long microsec) {
5656
else if (microsec > SECOND) {
5757
double seconds = microsec / (double)SECOND;
5858

59-
sprintf(buffer, "%.2f sec", seconds);
59+
snprintf(buffer, sizeof(buffer), "%.2f sec", seconds);
6060

6161
return std::string(buffer);
6262
}
@@ -65,7 +65,7 @@ inline std::string pretty_time(long long microsec) {
6565
else if (microsec > MILLIS) {
6666
double millis = microsec / (double)MILLIS;
6767

68-
sprintf(buffer, "%.2f ms", millis);
68+
snprintf(buffer, sizeof(buffer), "%.2f ms", millis);
6969

7070
return std::string(buffer);
7171
}
@@ -74,9 +74,8 @@ inline std::string pretty_time(long long microsec) {
7474
else {
7575
double micros = microsec;
7676

77-
sprintf(buffer, "%.2f µs", micros); // note the nifty unicode \mu. I
78-
// apologize when this breaks something
79-
// later.
77+
snprintf(buffer, sizeof(buffer), "%.2f µs",
78+
micros); // note the nifty unicode \mu. I apologize when this breaks something later.
8079

8180
return std::string(buffer);
8281
}

0 commit comments

Comments
 (0)