forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Possible bug in SDK with If statement logic?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
SamuraiX



Joined: 31 Jan 2006
Posts: 76
Location: USA

PostPosted: Tue Jun 27, 2006 12:52 am    Post subject: Possible bug in SDK with If statement logic? Reply with quote

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
View user's profile Send private message Visit poster's website
jimparis



Joined: 10 Jun 2005
Posts: 1179
Location: Boston

PostPosted: Tue Jun 27, 2006 7:29 am    Post subject: Reply with quote

You have a statement of the form
Code:
if(a && b || c)
and you rewrote it as
Code:
if(a && (b || c))
The 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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group