|
76 | 76 | #include "storage/ndb/include/mgmcommon/NdbMgm.hpp"
|
77 | 77 | #include "../src/mgmapi/mgmapi_configuration.hpp"
|
78 | 78 | #include "../src/mgmsrv/ConfigInfo.hpp"
|
| 79 | +#include "../src/mgmsrv/InitConfigFileParser.hpp" |
79 | 80 | #include <NdbAutoPtr.hpp>
|
80 | 81 | #include <NdbTCP.h>
|
81 | 82 | #include <inttypes.h>
|
| 83 | +#include "util/cstrbuf.h" |
82 | 84 |
|
83 | 85 | #include "my_alloc.h"
|
84 | 86 |
|
@@ -380,7 +382,6 @@ print_diff(const ndb_mgm_configuration_iterator& iter)
|
380 | 382 | Uint64 val64;
|
381 | 383 | const char* config_value;
|
382 | 384 | const char* node_type = nullptr;
|
383 |
| - char str[300] = {0}; |
384 | 385 |
|
385 | 386 | if (iter.get(CFG_TYPE_OF_SECTION, &val32) == 0)
|
386 | 387 | {
|
@@ -418,58 +419,41 @@ print_diff(const ndb_mgm_configuration_iterator& iter)
|
418 | 419 | ||
|
419 | 420 | (g_section == CFG_SECTION_SYSTEM))
|
420 | 421 | {
|
| 422 | + cstrbuf<20 + 1> str_buf; // enough for 64-bit decimal number |
| 423 | + const char* str = nullptr; |
421 | 424 | if (iter.get(ConfigInfo::m_ParamInfo[p]._paramId, &val32) == 0)
|
422 | 425 | {
|
423 |
| - sprintf(str, "%u", val32); |
| 426 | + require(str_buf.appendf("%u", val32) == 0); |
| 427 | + str = str_buf.c_str(); |
424 | 428 | }
|
425 | 429 | else if (iter.get(ConfigInfo::m_ParamInfo[p]._paramId, &val64) == 0)
|
426 | 430 | {
|
427 |
| - sprintf(str, "%llu", val64); |
| 431 | + require(str_buf.appendf("%ju", uintmax_t{val64}) == 0); |
| 432 | + str = str_buf.c_str(); |
428 | 433 | }
|
429 | 434 | else if (iter.get(ConfigInfo::m_ParamInfo[p]._paramId, &config_value) == 0)
|
430 | 435 | {
|
431 |
| - strncpy(str, config_value,300); |
| 436 | + str = config_value; |
432 | 437 | }
|
433 | 438 | else
|
434 | 439 | {
|
435 | 440 | continue;
|
436 | 441 | }
|
| 442 | + require(str != nullptr); |
437 | 443 |
|
438 | 444 | if ((MANDATORY != ConfigInfo::m_ParamInfo[p]._default)
|
439 | 445 | && (ConfigInfo::m_ParamInfo[p]._default)
|
440 | 446 | && strlen(ConfigInfo::m_ParamInfo[p]._default) > 0
|
441 |
| - && !strcmp(node_type, ConfigInfo::m_ParamInfo[p]._section) |
442 |
| - && strcmp(str, ConfigInfo::m_ParamInfo[p]._default) ) |
| 447 | + && strcmp(node_type, ConfigInfo::m_ParamInfo[p]._section) == 0 |
| 448 | + && strcmp(str, ConfigInfo::m_ParamInfo[p]._default) != 0) |
443 | 449 | {
|
444 |
| - char parse_str[300] = {0}; |
445 |
| - bool convert_bytes = false; |
446 |
| - uint64 memory_convert = 0; |
447 |
| - uint64 def_value = 0; |
448 |
| - uint len = strlen(ConfigInfo::m_ParamInfo[p]._default) - 1; |
449 |
| - strncpy(parse_str, ConfigInfo::m_ParamInfo[p]._default,299); |
450 |
| - if (parse_str[len] == 'M' || parse_str[len] == 'm') |
| 450 | + Uint64 value; |
| 451 | + if (InitConfigFileParser::convertStringToUint64(str, value)) |
451 | 452 | {
|
452 |
| - memory_convert = 1048576; |
453 |
| - convert_bytes = true; |
454 |
| - } |
455 |
| - if (parse_str[len] == 'K' || parse_str[len] == 'k') |
456 |
| - { |
457 |
| - memory_convert = 1024; |
458 |
| - convert_bytes = true; |
459 |
| - } |
460 |
| - if (parse_str[len] == 'G' || parse_str[len] == 'g') |
461 |
| - { |
462 |
| - memory_convert = 1099511627776ULL; |
463 |
| - convert_bytes = true; |
464 |
| - } |
465 |
| - |
466 |
| - if (convert_bytes) |
467 |
| - { |
468 |
| - parse_str[len] = '\0'; |
469 |
| - def_value = atoi(parse_str); |
470 |
| - memory_convert = memory_convert * def_value; |
471 |
| - BaseString::snprintf(parse_str, 299, "%" PRIu64, memory_convert); |
472 |
| - if (!strcmp(str, parse_str)) |
| 453 | + const char* def_str = ConfigInfo::m_ParamInfo[p]._default; |
| 454 | + Uint64 def_value; |
| 455 | + require(InitConfigFileParser::convertStringToUint64(def_str, def_value)); |
| 456 | + if (value == def_value) |
473 | 457 | {
|
474 | 458 | continue;
|
475 | 459 | }
|
|
0 commit comments