Skip to content

battery: fixup some warnings

Landry Breuil requested to merge landry/upower:fix/abswarn into master

building natively on OpenBSD with clang 13, i get those warnings:

../src/up-device-battery.c:128:53: warning: absolute value function 'abs' given an argument of type 'gint64' (aka 'long long') but has parameter of type 'int' which may cause truncation of value [-Wabsolute-value]
                if (abs(UP_DAEMON_LONG_TIMEOUT * G_USEC_PER_SEC - abs (td)) > abs(UP_DAEMON_SHORT_TIMEOUT * G_USEC_PER_SEC - ref_td))
                                                                  ^
../src/up-device-battery.c:128:53: note: use function 'llabs' instead
                if (abs(UP_DAEMON_LONG_TIMEOUT * G_USEC_PER_SEC - abs (td)) > abs(UP_DAEMON_SHORT_TIMEOUT * G_USEC_PER_SEC - ref_td))
                                                                  ^~~
                                                                  llabs

../src/up-device-battery.c:128:65: warning: absolute value function 'abs' given an argument of type 'long long' but has parameter of type 'int' which may cause truncation of value [-Wabsolute-value]
                if (abs(UP_DAEMON_LONG_TIMEOUT * G_USEC_PER_SEC - abs (td)) > abs(UP_DAEMON_SHORT_TIMEOUT * G_USEC_PER_SEC - ref_td))
                                                                              ^
../src/up-device-battery.c:128:65: note: use function 'llabs' instead
                if (abs(UP_DAEMON_LONG_TIMEOUT * G_USEC_PER_SEC - abs (td)) > abs(UP_DAEMON_SHORT_TIMEOUT * G_USEC_PER_SEC - ref_td))
                                                                              ^~~
                                                                              llabs

../src/up-device-battery.c:158:7: warning: using integer absolute value function 'abs' when argument is of floating point type [-Wabsolute-value]
                if (abs(energy_rate) < 0.5)
                    ^
../src/up-device-battery.c:158:7: note: use function 'fabs' instead
                if (abs(energy_rate) < 0.5)
                    ^~~
                    fabs

../src/up-device-battery.c:158:7: note: include the header <math.h> or explicitly provide a declaration for 'fabs'
3 warnings generated.

Merge request reports