You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
it is possible to enter an older Add token than an entered Set token in the C implementation. I figured out that the MarkCountAsUsed() function is not working properly.
The macro CHECK_BIT(variable, position) is not good.
#define CHECK_BIT(variable, position) (((variable) >> (position)) & 1)
int test = 0;
test = CHECK_BIT(0b111, 2);
test will be 4. That's ok if you use the check only in if() but it will be used also in the SET_BIT(variable,position,value) as value and the value should only be 1 or 0. That leads to
#define SET_BIT(variable,position,value) (variable & ~(1<<position)) | (value<<position)
#define CHECK_BIT(variable, position) (((variable) >> (position)) & 1)
int test = 0;
test = SET_BIT(0b0,0,CHECK_BIT(0b111, 2));
and test will be 0b100 and not 0b1 as expected.
Also the for loop is not working correct.
The function will still not work correctly with the new CHECK_BIT macro from above.
After the first example, the counts 33 and 34 will should be marked. Count 33 will set UsedCounts to 0b1111111111111111, that's correct, but count 34 will set it to 0b111111111111101 so that count 32 is marked as unused, which is not correct.
If the for loop will be changed to following, it will work
for(int i=RelativeCount+1; i < MAX_UNUSED_OLDER_TOKENS - RelativeCount; i++) {
NewUsedCount = SET_BIT(NewUsedCount, i, CHECK_BIT(*UsedCounts, i-RelativeCount));
}
Regards Jonas
The text was updated successfully, but these errors were encountered:
JoLo33
changed the title
CHECK_BIT macro in opaygo_decoder is not good
MarkCountAsUsed() function is not working properly
Aug 26, 2022
JoLo33
added a commit
to JoLo33/OpenPAYGO-HW
that referenced
this issue
Aug 29, 2022
changed: CHECK_BIT macro, return only 0 or 1
changed: for loop in MarkCountAsUsed, so that the correct counts are marked
changed: IsCountValid, so that the limits are correct as explained in general documentation
Hey,
it is possible to enter an older Add token than an entered Set token in the C implementation. I figured out that the MarkCountAsUsed() function is not working properly.
The macro CHECK_BIT(variable, position) is not good.
test will be 4. That's ok if you use the check only in if() but it will be used also in the SET_BIT(variable,position,value) as value and the value should only be 1 or 0. That leads to
and test will be 0b100 and not 0b1 as expected.
Also the for loop is not working correct.
The function will still not work correctly with the new CHECK_BIT macro from above.
There are two problems:
1.
After this, UsedCounts is 0b10000000, but that is wrong because counts 4 and 8 are now marked as unused again.
After the first example, the counts 33 and 34 will should be marked. Count 33 will set UsedCounts to 0b1111111111111111, that's correct, but count 34 will set it to 0b111111111111101 so that count 32 is marked as unused, which is not correct.
If the for loop will be changed to following, it will work
Regards Jonas
The text was updated successfully, but these errors were encountered: