dethrace-labs / dethrace

Reverse engineering the 1997 game "Carmageddon"
https://twitter.com/dethrace_labs
GNU General Public License v3.0
669 stars 38 forks source link

Verify warnings in car.c #319

Closed madebr closed 1 year ago

madebr commented 1 year ago

Building dethrace with clang/apple-clang emits -Wabsolute-value warnings in car.c. These are about taking the absolute value of an unsigned number, which is a no-op.

Should this warning be silinced (through a pragma)? Or should the argument to abs first be casted to a signed int?

[143/210] Building C object src/DETHRACE/CMakeFiles/dethrace_obj.dir/common/car.c.o
/home/maarten/projects/dethrace/src/DETHRACE/common/car.c:4619:13: warning: taking the absolute value of unsigned type 'unsigned int' has no effect [-Wabsolute-value]
        if (abs(GetTotalTime() - next_incident_time) > 2500) {
            ^
/home/maarten/projects/dethrace/src/DETHRACE/common/car.c:4619:13: note: remove the call to 'abs' since unsigned values cannot be negative
        if (abs(GetTotalTime() - next_incident_time) > 2500) {
            ^~~
/home/maarten/projects/dethrace/src/DETHRACE/common/car.c:4645:13: warning: taking the absolute value of unsigned type 'unsigned int' has no effect [-Wabsolute-value]
        if (abs(GetTotalTime() - next_incident_time) > 2500) {
            ^
/home/maarten/projects/dethrace/src/DETHRACE/common/car.c:4645:13: note: remove the call to 'abs' since unsigned values cannot be negative
        if (abs(GetTotalTime() - next_incident_time) > 2500) {
            ^~~
/home/maarten/projects/dethrace/src/DETHRACE/common/car.c:4656:13: warning: taking the absolute value of unsigned type 'unsigned int' has no effect [-Wabsolute-value]
        if (abs(GetTotalTime() - next_incident_time) > 2500) {
            ^
/home/maarten/projects/dethrace/src/DETHRACE/common/car.c:4656:13: note: remove the call to 'abs' since unsigned values cannot be negative
        if (abs(GetTotalTime() - next_incident_time) > 2500) {
            ^~~
/home/maarten/projects/dethrace/src/DETHRACE/common/car.c:4706:13: warning: taking the absolute value of unsigned type 'tU32' (aka 'unsigned int') has no effect [-Wabsolute-value]
        if (abs(*next_incident_time) > 2500) {
            ^
/home/maarten/projects/dethrace/src/DETHRACE/common/car.c:4706:13: note: remove the call to 'abs' since unsigned values cannot be negative
        if (abs(*next_incident_time) > 2500) {
            ^~~
/home/maarten/projects/dethrace/src/DETHRACE/common/car.c:4710:44: warning: taking the absolute value of unsigned type 'tU32' (aka 'unsigned int') has no effect [-Wabsolute-value]
            for (test = 0; GetNextIncident(abs(t), &type2, &severity2, &info2, &next_incident_time2) && test <= 10 && abs(next_incident_time2) <= 3500; test++) {
                                           ^
/home/maarten/projects/dethrace/src/DETHRACE/common/car.c:4710:44: note: remove the call to 'abs' since unsigned values cannot be negative
            for (test = 0; GetNextIncident(abs(t), &type2, &severity2, &info2, &next_incident_time2) && test <= 10 && abs(next_incident_time2) <= 3500; test++) {
                                           ^~~
/home/maarten/projects/dethrace/src/DETHRACE/common/car.c:4710:119: warning: taking the absolute value of unsigned type 'tU32' (aka 'unsigned int') has no effect [-Wabsolute-value]
            for (test = 0; GetNextIncident(abs(t), &type2, &severity2, &info2, &next_incident_time2) && test <= 10 && abs(next_incident_time2) <= 3500; test++) {
                                                                                                                      ^
/home/maarten/projects/dethrace/src/DETHRACE/common/car.c:4710:119: note: remove the call to 'abs' since unsigned values cannot be negative
            for (test = 0; GetNextIncident(abs(t), &type2, &severity2, &info2, &next_incident_time2) && test <= 10 && abs(next_incident_time2) <= 3500; test++) {
                                                                                                                      ^~~
/home/maarten/projects/dethrace/src/DETHRACE/common/car.c:4719:17: warning: taking the absolute value of unsigned type 'tU32' (aka 'unsigned int') has no effect [-Wabsolute-value]
            if (abs(*next_incident_time) > 2500) {
                ^
/home/maarten/projects/dethrace/src/DETHRACE/common/car.c:4719:17: note: remove the call to 'abs' since unsigned values cannot be negative
            if (abs(*next_incident_time) > 2500) {
                ^~~
/home/maarten/projects/dethrace/src/DETHRACE/common/car.c:4727:65: warning: taking the absolute value of unsigned type 'tU32' (aka 'unsigned int') has no effect [-Wabsolute-value]
                    ScanCarsPositions(c, &c->pos, 100000.f, -1, abs(*next_incident_time), &pos, &t);
                                                                ^
/home/maarten/projects/dethrace/src/DETHRACE/common/car.c:4727:65: note: remove the call to 'abs' since unsigned values cannot be negative
                    ScanCarsPositions(c, &c->pos, 100000.f, -1, abs(*next_incident_time), &pos, &t);
                                                                ^~~
/home/maarten/projects/dethrace/src/DETHRACE/common/car.c:4861:52: warning: taking the absolute value of unsigned type 'unsigned int' has no effect [-Wabsolute-value]
                ScanCarsPositions(c, &tv, 10000.f, abs(t2 - GetTotalTime()), time_step, &tv2, &time);
                                                   ^
/home/maarten/projects/dethrace/src/DETHRACE/common/car.c:4861:52: note: remove the call to 'abs' since unsigned values cannot be negative
                ScanCarsPositions(c, &tv, 10000.f, abs(t2 - GetTotalTime()), time_step, &tv2, &time);
                                                   ^~~
9 warnings generated.

The warnings are all in action replay camera functions.