Skip to content

Avoid 'conversion may change value' cases related to MountMan

Toni Asensi Esteve requested to merge work/conversion_mountman into master

Avoid 'conversion may change value' cases related to MountMan: main

While we are at it, solve two 'signedness warnings': while_we_are_at_it

and use a better way to round (as it was asked in the "insert a good round function here" comment in the source code).

Note: About the roundl() function, some examples can be seen on https://www.cplusplus.com/reference/cmath/round/

TEST PLAN

Go to Tools > Open MountMan... > MountMan, check that sizes and percentages are correct.
Mount a filesystem. Go again to Tools > Open MountMan... > MountMan, check that sizes and percentages are correct. Unmount the filesystem.

This program can also be used in order to test similar rounding operations:

    #include <QDebug>

    #include <math.h>

    int main()
    {
        unsigned long TotalBlks = 7;
        unsigned long FreeBlks = 3;
        // Note: qDebug() didn't print "long doubles", consequently "double" is used in the next line
        qDebug() << (static_cast<double>(TotalBlks - FreeBlks) * 100) / TotalBlks;
        qDebug() << "After being rounded:";
        qDebug() << static_cast<int>(roundl((static_cast<long double>(TotalBlks - FreeBlks) * 100) / TotalBlks));
        qDebug() << "---";

        TotalBlks = 8;
        FreeBlks = 3;
        qDebug() << (static_cast<double>(TotalBlks - FreeBlks) * 100) / TotalBlks;
        qDebug() << "After being rounded:";
        qDebug() << static_cast<int>(roundl((static_cast<long double>(TotalBlks - FreeBlks) * 100) / TotalBlks));
        qDebug() << "---";

        TotalBlks = 9;
        FreeBlks = 3;
        qDebug() << (static_cast<double>(TotalBlks - FreeBlks) * 100) / TotalBlks;
        qDebug() << "After being rounded:";
        qDebug() << static_cast<int>(roundl((static_cast<long double>(TotalBlks - FreeBlks) * 100) / TotalBlks));
        qDebug() << "---";

        return EXIT_SUCCESS;
    }

which prints the expected results:

    57.1429
    After being rounded:
    57
    ---
    62.5
    After being rounded:
    63
    ---
    66.6667
    After being rounded:
    67
    ---
Edited by Toni Asensi Esteve

Merge request reports