| View previous topic :: View next topic |
| Author |
Message |
Dark Byte Site Admin
Reputation: 475
Joined: 09 May 2003 Posts: 25987 Location: The netherlands
|
Posted: Sat Jul 18, 2009 6:16 pm Post subject: Weird bug: increase with conditional value makes value 0 |
|
|
| Code: |
bx_phy_address pAddr = vm->msr_bitmap_addr + (msr >> 3) + (op == VMX_VMEXIT_RDMSR) ? 0 : 2048;
|
vm->msr_bitmap_addr contains a valid value (not even near 0xffffffff)
(op == VMX_VMEXIT_RDMSR) will evaluate possitive
after execution, pAddr == 0
the following code:
| Code: |
bx_phy_address pAddr = vm->msr_bitmap_addr + (msr >> 3);
printf("1:pAddr =%x\n",pAddr );
pAddr=pAddr+(op == VMX_VMEXIT_RDMSR) ? 0 : 2048;
printf("2:pAddr =%x\n",pAddr );
|
shows :
1:pAddr=1f86b02f
2:pAddr=0
buf if I do this:
| Code: |
bx_phy_address pAddr = vm->msr_bitmap_addr + (msr >> 3) + ((op == VMX_VMEXIT_RDMSR) ? 0 : 2048);
|
It'll work fine
So, can anyone explain WHY this is happening?
GCC 4.4.0
_________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sat Jul 18, 2009 6:20 pm Post subject: |
|
|
is it checking the conditional value after it adds instead of before? in the second code its checking the value of just the second phrase(on my phone so idk the phrase). it seems like an order of operations issue? edit: im pretty sure its an operation order issue. its doing the conditional after the add and not doing the conditional then the add
_________________
Last edited by HomerSexual on Sat Jul 18, 2009 6:23 pm; edited 1 time in total |
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sat Jul 18, 2009 6:23 pm Post subject: |
|
|
| it should be the same so i am assuming it is a problem with the compiler. what i would do is debug it in ollydbg and see what code is different when using each of those
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Sat Jul 18, 2009 6:24 pm Post subject: |
|
|
well assuming the compiler is correct its order of ops. the code is NOT the same because the parenthesis make it so the condition happens before the addition
_________________
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 475
Joined: 09 May 2003 Posts: 25987 Location: The netherlands
|
Posted: Sat Jul 18, 2009 6:26 pm Post subject: |
|
|
yes, I think somehow the compiler is seeing it like this:
bx_phy_address pAddr = (vm->msr_bitmap_addr + (msr >> 3) + (op == VMX_VMEXIT_RDMSR)) ? 0 : 2048;
instead of
bx_phy_address pAddr = vm->msr_bitmap_addr + (msr >> 3) + ((op == VMX_VMEXIT_RDMSR) ? 0 : 2048);
_________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sat Jul 18, 2009 6:42 pm Post subject: |
|
|
lol.. i was reading it like that too haha. main reason is that i didn't know you can do conditional assignment without binding the result to a variable.. ie. the last bit :
((op == VMX_VMEXIT_RDMSR) ? 0 : 2048)
the result is not bound, are you sure you can do that ?
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 475
Joined: 09 May 2003 Posts: 25987 Location: The netherlands
|
Posted: Sat Jul 18, 2009 6:44 pm Post subject: |
|
|
yes, ((op == VMX_VMEXIT_RDMSR) ? 0 : 2048) works fine
if (op == VMX_VMEXIT_RDMSR) then that whole block gets replaced by a 0, else it becomes 2048
_________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sat Jul 18, 2009 6:54 pm Post subject: |
|
|
This happens on the MS compiler as well (and every compiler I would imagine)
| Code: | DWORD test = 0x00102030;
test = test + (0xF3 == 0xFF) ? 0 : 1;
printf("%x", test); |
test will become 0 here.
instead of this, which is what would make sense to me for it to boil down to... but mathematical precedence disagrees apparently.
| Code: | | test = test + ((0xF3 == 0xFF) ? 0 : 1); |
http://en.wikipedia.org/wiki/Order_of_operations#Mathematical_precedence
Last edited by hcavolsdsadgadsg on Sat Jul 18, 2009 8:40 pm; edited 1 time in total |
|
| Back to top |
|
 |
BanMe Master Cheater
Reputation: 0
Joined: 29 Nov 2005 Posts: 375 Location: Farmington NH, USA
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sat Jul 18, 2009 8:32 pm Post subject: |
|
|
| BanMe wrote: | Slovach that is because your logic just failed you..
F3 will Never = FF.. so there for always 0..and I think something along this line should work..
regards BanMe |
I know and it was intentional as I was just using it as an example.
| Code: | | test = test + ((0xF3 == 0xFF) ? 0 : 1); | will have test get the 1 added to it as it will evaluate to false.
| Code: | | test += (0xF3 == 0xFF) ? 0 : 1; |
this also will add the 1 as expected because of the +='s precedence.
|
|
| Back to top |
|
 |
BanMe Master Cheater
Reputation: 0
Joined: 29 Nov 2005 Posts: 375 Location: Farmington NH, USA
|
|
| Back to top |
|
 |
|