Skip to content

Commit c9bee9c

Browse files
author
Gonzalo Diaz
committed
[Hacker Rank]: Warmup: Plus Minus. Issues fixed:
* sonarlint: C-style array should not be used cpp:S5945 * sonarlint: Replace this macro by "const", "constexpr" or an "enum". Macros should not be used to define constants cpp:S5028
1 parent 5fbc28e commit c9bee9c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/lib/exercises/src/hackerrank/warmup/plus_minus.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
#include <string>
99
#include <vector>
1010

11-
#define BUFFER_MAX_SIZE 100
11+
const int BUFFER_MAX_SIZE = 10;
1212

1313
std::string format_result(double number) {
14-
char buffer[BUFFER_MAX_SIZE];
14+
std::string str;
15+
str.reserve(BUFFER_MAX_SIZE);
16+
char *buffer = str.data();
1517

1618
snprintf(buffer, BUFFER_MAX_SIZE, "%0.6lf", number);
17-
std::string formatted = buffer;
18-
19-
return formatted;
19+
return buffer;
2020
}
2121

2222
namespace hackerrank::warmup {

0 commit comments

Comments
 (0)