-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
find bug: Long integer digit decoding error #49
Comments
Hello @gaohtao, We need to review the remaining code, and create a test case for this. I guess in ISO 15118-2, |
I tested ISO15118-2 protocol SessionSetupRes command, which contains a timestamp defined as int64, I intentionally filled in the timestamp as largeInteger, and I found that the decoded number is wrong. |
The left-hand side of a left-shift operation only gets promoted up to "int", if too small to support the number of bits created. This leads to truncation in case of resulting values with more than 32 significant bits, which are expected in a 64-bit value decoder. Move the typecast to the left-shifted variable. Do the same for the 32-bit case, for consistency. Fixes #49 Signed-off-by: Moritz Barsnick <moritz.barsnick@chargebyte.com>
The left-hand side of a left-shift operation only gets promoted up to "int", if too small to support the number of bits created. This leads to truncation in case of resulting values with more than 32 significant bits, which are expected in a 64-bit value decoder. Move the typecast to the left-shifted variable. Do the same for the 32-bit case, for consistency. Fixes #49 Signed-off-by: Moritz Barsnick <moritz.barsnick@chargebyte.com>
This should be fixed on branch main with commit ae4f37e. Please be so kind to test. Thanks for your report! |
I used the C code generated by cbexigen and found that the encoding of long integer digits was correct, but the decoding process was wrong. When the number of long integers exceeds 15 digits, an integer overflow error occurs during the accumulation process, resulting in incorrect calculation results.
The correct code should be following:
int exi_basetypes_convert_64_from_unsigned(exi_unsigned_t* exi_unsigned, uint64_t* value)
{
if (exi_unsigned->octets_count > EXI_BASETYPES_UINT64_MAX_OCTETS)
{
return EXI_ERROR__OCTET_COUNT_LARGER_THAN_TYPE_SUPPORTS;
}
}
The text was updated successfully, but these errors were encountered: