| View previous topic :: View next topic |
| Author |
Message |
SamuraiX
Joined: 31 Jan 2006 Posts: 76 Location: USA
|
Posted: Tue Jun 27, 2006 12:52 am Post subject: Possible bug in SDK with If statement logic? |
|
|
I think I found a bug in the SDK. While the compiler does not complain, the psp is crashing within executing this if statement. The fix that I found was to be more detailed within the If statement. Running the same code for dos there was no issue with the original code.
original
| Code: | int player_check_energy(int which, int ani){
if(
self->model->animation[ani] &&
(which &&
self->model->animation[ani]->mponly != 2 &&
self->mp > self->model->animation[ani]->energycost) ||
(!which &&
self->model->animation[ani]->mponly != 1 &&
self->health > self->model->animation[ani]->energycost)
)
return 1;
return 0;
} |
to the new version
| Code: | int player_check_energy(int which, int ani){
if(
self->model->animation[ani] &&
((which &&
(self->model->animation[ani]->mponly != 2) &&
(self->mp > self->model->animation[ani]->energycost)) ||
(!which &&
(self->model->animation[ani]->mponly != 1) &&
(self->health > self->model->animation[ani]->energycost)))
)
return 1;
return 0;
} |
|
|
| Back to top |
|
 |
jimparis
Joined: 10 Jun 2005 Posts: 1179 Location: Boston
|
Posted: Tue Jun 27, 2006 7:29 am Post subject: |
|
|
You have a statement of the formand you rewrote it asThe compiler didn't complain because what you wrote is technically valid, but the order of operations isn't what you expected. If you were to have compiled this with all warnings enabled (-Wall) you get the very clear warning: | Code: | test.c: In function ‘player_check_energy’:
test.c:14: warning: suggest parentheses around && within || | This isn't a SDK bug. |
|
| Back to top |
|
 |
|