3939 */
4040
4141#include " base/string/cstring.h"
42+ #include " base/basic_types.h"
43+ #include < algorithm>
4244#include < cctype>
4345#include < cstdio>
44- #include < sstream >
46+ #include < cstdlib >
4547#include < cstring>
48+ #include < sstream>
49+ #include < string>
50+
51+ constexpr size_t NUMBER_TO_STRING_BUFFER_SIZE = 32 ;
52+
53+ // NOLINTBEGIN (*-c-arrays)
4654
4755namespace MaxPlus {
4856
@@ -81,8 +89,8 @@ MPString::MPString(const MPString &s) = default;
8189 * Constructor.
8290 */
8391MPString::MPString (const int n) {
84- char str[32 ];
85- snprintf (&str[0 ], 32 , " %i" , n);
92+ char str[NUMBER_TO_STRING_BUFFER_SIZE ];
93+ snprintf (&str[0 ], NUMBER_TO_STRING_BUFFER_SIZE , " %i" , n);
8694 append (std::string (str));
8795}
8896
@@ -91,8 +99,8 @@ MPString::MPString(const int n) {
9199 * Constructor.
92100 */
93101MPString::MPString (const unsigned int n) {
94- char str[32 ];
95- snprintf (&str[0 ], 32 , " %u" , n);
102+ char str[NUMBER_TO_STRING_BUFFER_SIZE ];
103+ snprintf (&str[0 ], NUMBER_TO_STRING_BUFFER_SIZE , " %u" , n);
96104 append (std::string (str));
97105}
98106
@@ -101,8 +109,8 @@ MPString::MPString(const unsigned int n) {
101109 * Constructor.
102110 */
103111MPString::MPString (const long int n) {
104- char str[32 ];
105- snprintf (&str[0 ], 32 , " %ld" , n);
112+ char str[NUMBER_TO_STRING_BUFFER_SIZE ];
113+ snprintf (&str[0 ], NUMBER_TO_STRING_BUFFER_SIZE , " %ld" , n);
106114 append (std::string (str));
107115}
108116
@@ -111,8 +119,8 @@ MPString::MPString(const long int n) {
111119 * Constructor.
112120 */
113121MPString::MPString (const unsigned long int n) {
114- char str[32 ];
115- snprintf (&str[0 ], 32 , " %ld" , n);
122+ char str[NUMBER_TO_STRING_BUFFER_SIZE ];
123+ snprintf (&str[0 ], NUMBER_TO_STRING_BUFFER_SIZE , " %ld" , n);
116124 append (std::string (str));
117125}
118126
@@ -121,8 +129,8 @@ MPString::MPString(const unsigned long int n) {
121129 * Constructor.
122130 */
123131MPString::MPString (const long long int n) {
124- char str[32 ];
125- snprintf (&str[0 ], 32 , " %lld" , n);
132+ char str[NUMBER_TO_STRING_BUFFER_SIZE ];
133+ snprintf (&str[0 ], NUMBER_TO_STRING_BUFFER_SIZE , " %lld" , n);
126134 append (std::string (str));
127135}
128136
@@ -131,8 +139,8 @@ MPString::MPString(const long long int n) {
131139 * Constructor.
132140 */
133141MPString::MPString (const unsigned long long int n) {
134- char str[32 ];
135- snprintf (&str[0 ], 32 , " %lld" , n);
142+ char str[NUMBER_TO_STRING_BUFFER_SIZE ];
143+ snprintf (&str[0 ], NUMBER_TO_STRING_BUFFER_SIZE , " %lld" , n);
136144 append (std::string (str));
137145}
138146
@@ -141,8 +149,8 @@ MPString::MPString(const unsigned long long int n) {
141149 * Constructor.
142150 */
143151MPString::MPString (const CDouble n) {
144- char str[32 ];
145- snprintf (&str[0 ], 32 , " %g" , n);
152+ char str[NUMBER_TO_STRING_BUFFER_SIZE ];
153+ snprintf (&str[0 ], NUMBER_TO_STRING_BUFFER_SIZE , " %g" , n);
146154 append (std::string (str));
147155}
148156
@@ -566,3 +574,5 @@ MPString MPString::regexReplaceMultiLine(const MPString ®ex, const MPString &
566574}
567575
568576} // namespace MaxPlus
577+
578+ // NOLINTEND (*-c-arrays)
0 commit comments