Skip to content
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

Error in util.Set_String and util.Get_String #479

Open
PoitrasJ opened this issue Dec 6, 2023 · 1 comment
Open

Error in util.Set_String and util.Get_String #479

PoitrasJ opened this issue Dec 6, 2023 · 1 comment
Milestone

Comments

@PoitrasJ
Copy link

PoitrasJ commented Dec 6, 2023

When reading the first Byte in the ByteArray, which contains the maximum length of the string, the Hexadecimal value is sometimes in a format that Python will not cast to Integer : b'\ff' will stay the type "Bytes" and the slice access fails.

this Section in set_string

    # fill the rest with empty space
    for r in range(i + 1, (bytearray_[byte_index]) - 2):
        bytearray_[byte_index + 2 + r] = ord(' ')

this Section in get_string

    str_length = int(bytearray_[byte_index + 1])
    max_string_size = int(bytearray_[byte_index])

The solution i came up is to evaluate the value using ord :

    # fill the rest with empty space
    for r in range(i + 1, ord(bytearray_[byte_index]) - 2):
        bytearray_[byte_index + 2 + r] = ord(' ')
    str_length = ord(bytearray_[byte_index + 1])
    max_string_size = ord(bytearray_[byte_index])
@gijzelaerr gijzelaerr added this to the 1.5 milestone May 2, 2024
@gijzelaerr
Copy link
Owner

Can you supply a unit test or string to break the current behaviour?

@gijzelaerr gijzelaerr modified the milestones: 1.5, 2.1 Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants