managarm / frigg

Lightweight C++ utilities and algorithms for system programming
MIT License
56 stars 20 forks source link

formatting.hpp: Assertion failure #11

Closed Dennisbonke closed 3 years ago

Dennisbonke commented 3 years ago

While running nyancat on Managarm, the following assertion failure message is printed continuously:

../../../src/mlibc/subprojects/frigg/include/frg/formatting.hpp:231: Assertion 'padding == ' '' failed!

Relevant code snippet for context:

template<typename P, typename T>
    void print_float(P &formatter, T number, int width = 0, int precision = 6,
            char padding = ' ', bool left_justify = false, bool use_capitals = false,
            bool group_thousands = false, locale_options locale_opts = {}) {
        (void)group_thousands;
        FRG_DEBUG_ASSERT(padding == ' '); // <-- This assert fails

        bool has_sign = false;
        if (number < 0) {
            formatter.append('-');
            has_sign = true;
        }

        bool inf = __builtin_isinf(number), nan = __builtin_isnan(number);
        if (inf || nan) {
            auto total_length = 3 + has_sign;
            auto pad_length = width > total_length ? width - total_length : 0;
            if (!left_justify) {
                while (pad_length > 0) {
                    formatter.append(padding);
                    pad_length--;
                }
            }

            if (inf)
                formatter.append(use_capitals ? "INF" : "inf");
            else
                formatter.append(use_capitals ? "NAN" : "nan");

            if (left_justify) {
                while (pad_length > 0) {
                    formatter.append(padding);
                    pad_length--;
                }
            }

            return;
        }