From 9e08f40a1053b7db053f3877c4a6d4672a9681c9 Mon Sep 17 00:00:00 2001 From: "Fred T. Hamster" Date: Sun, 8 Feb 2026 00:06:07 -0500 Subject: [PATCH] ini config test is working again the test exposed an insufficient size when performing double_plus operations, since we shifted the number into an int as part of truncation operation. changed this to a long long instead, which seems to have sufficient size for our purposes. previous result was that it was garbling the number and turning it negative as it handily overflowed 32 bits. --- nucleus/library/basis/astring.cpp | 12 +++++-- nucleus/library/mathematics/math_ops.h | 10 +++--- .../test_ini_configurator.cpp | 31 ++++++++++++++----- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/nucleus/library/basis/astring.cpp b/nucleus/library/basis/astring.cpp index 3fdf4437..16a6e3c7 100644 --- a/nucleus/library/basis/astring.cpp +++ b/nucleus/library/basis/astring.cpp @@ -180,8 +180,14 @@ astring &astring::sprintf(const char *initial, ...) return to_return; } +//#pragma temporary debug in astring!!! +//#define DEBUG_STRING + astring &astring::base_sprintf(const char *initial, va_list &args) { +#ifdef DEBUG_STRING + printf("base_sprintf entry, format string is: %s\n", initial); +#endif reset(); if (!initial) return *this; // skip null strings. if (!initial[0]) return *this; // skip empty strings. @@ -192,7 +198,7 @@ astring &astring::base_sprintf(const char *initial, va_list &args) // thanks for the inspiration to k&r page 156. for (const char *traverser = initial; *traverser; traverser++) { #ifdef DEBUG_STRING - printf("index=%d, char=%c\n", traverser - initial, *traverser); + printf("index=%d, char=%c\n", int(traverser - initial), *traverser); #endif if (*traverser != '%') { @@ -202,7 +208,7 @@ astring &astring::base_sprintf(const char *initial, va_list &args) } traverser++; // go to the next character. #ifdef DEBUG_STRING - printf("index=%d, char=%c\n", traverser - initial, *traverser); + printf("index=%d, char=%c\n", int(traverser - initial), *traverser); #endif if (*traverser == '%') { // capture the "%%" style format specifier. @@ -323,6 +329,8 @@ void astring::seek_modifier(const char *&traverser, char *modifier_chars) #endif } +//#undef DEBUG_STRING + void astring::get_type_character(const char * &traverser, va_list &args, astring &output_string, const char *flag_chars, const char *width_chars, const char *precision_chars, const char *modifier_chars) diff --git a/nucleus/library/mathematics/math_ops.h b/nucleus/library/mathematics/math_ops.h index b2f7f879..a449e326 100644 --- a/nucleus/library/mathematics/math_ops.h +++ b/nucleus/library/mathematics/math_ops.h @@ -24,19 +24,21 @@ namespace mathematics { class math_ops { public: + typedef signed long long fat_int; + //! returns the rounded integer value for "to_round". - static int round_it(float to_round) + static fat_int round_it(float to_round) { - int to_return = int(to_round); + fat_int to_return = fat_int(to_round); // this uses a simplistic view of rounding. if (to_round - float(to_return) > 0.5) to_return++; return to_return; } //! returns the rounded integer value for "to_round". - static int round_it(double to_round) + static fat_int round_it(double to_round) { - int to_return = int(to_round); + fat_int to_return = fat_int(to_round); // this uses a simplistic view of rounding. if (to_round - double(to_return) > 0.5) to_return++; return to_return; diff --git a/nucleus/library/tests_configuration/test_ini_configurator.cpp b/nucleus/library/tests_configuration/test_ini_configurator.cpp index 344cbce3..184204a8 100644 --- a/nucleus/library/tests_configuration/test_ini_configurator.cpp +++ b/nucleus/library/tests_configuration/test_ini_configurator.cpp @@ -36,6 +36,8 @@ const int test_iterations = 10; #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s) +#define UNWANTED_DEFAULT_VALUE 9949494.3 + HOOPLE_STARTUP_CODE; using namespace basis; @@ -54,6 +56,8 @@ const char *INI_SECTION = "t_ini_configurator"; //hmmm: ugly old main() without using the hoople machinery. ack. astring static_class_name() { return "test_ini_configurator"; } +#define MACRO_AS_STRING(s) #s + int main(int formal(argc), char *formal(argv)[]) { FUNCDEF("test ini config main") @@ -115,9 +119,9 @@ LOG(astring("exe directory is currently: ") + application_configuration::applica frunkle def_frunkle(3.14159265358); astring def_text(astring::SPRINTF, "%f", def_frunkle.value()); ini.store(INI_SECTION, TEST_NAME, def_text); - astring found_string = ini.load(INI_SECTION, TEST_NAME, "9949494.3"); + astring found_string = ini.load(INI_SECTION, TEST_NAME, MACRO_AS_STRING(UNWANTED_DEFAULT_VALUE)); frunkle found_frunkle = found_string.convert(0.0); - if (found_frunkle == frunkle(9949494.3)) + if (found_frunkle == frunkle(UNWANTED_DEFAULT_VALUE)) deadly_error(INI_SECTION, TEST_NAME, "ini_configurator load failed: default was used"); if (found_frunkle != def_frunkle) @@ -127,14 +131,27 @@ LOG(astring("exe directory is currently: ") + application_configuration::applica { // fourth test set. const char *TEST_NAME = "fourth test: frunkle"; - frunkle def_frunkle(1487335673.1415926535834985987); - astring def_text(astring::SPRINTF, "%f", def_frunkle.value()); + frunkle def_frunkle((double)1487335673.1415926535834985987); + astring def_text(astring::SPRINTF, "%f", def_frunkle.value()); +LOG(astring("def text is ") + def_text); +double comparator = 1487335673.1415926535834985987; +LOG(a_sprintf("starting from double gets %f instead", comparator)); + ini.store("test", "frunkle_test", def_text); - astring found_string = ini.load("test", "frunkle_test", "9949494.3"); + astring found_string = ini.load("test", "frunkle_test", MACRO_AS_STRING(UNWANTED_DEFAULT_VALUE)); + +LOG(astring("found string is ") + found_string); + frunkle found_frunkle = found_string.convert(0.0); - if (found_frunkle == frunkle(9949494.3)) + if (found_frunkle == frunkle(0.0)) + deadly_error(INI_SECTION, TEST_NAME, + "ini_configurator load failed: float conversion failed--got zero"); + +LOG(astring("found number ") + a_sprintf("%f", found_frunkle.value()) + " which we want to be " + a_sprintf("%f", def_frunkle.value())); + + if (found_frunkle == frunkle(UNWANTED_DEFAULT_VALUE)) deadly_error(INI_SECTION, TEST_NAME, - "ini_configurator load failed: wrong default was used"); + "ini_configurator load failed: wrong unwanted default was used"); if (found_frunkle != def_frunkle) deadly_error(INI_SECTION, TEST_NAME, "ini_configurator load failed: saved value differed"); -- 2.34.1