Skip to content

Extract values in HIDParse correctly when compiled in 64-bit (LP64) mode - #1024

Merged
jimklimov merged 2 commits into
networkupstools:masterfrom
nbriggs:issue_1015_big-endian-LP64
May 24, 2021
Merged

jimklimov merged 2 commits into
networkupstools:masterfrom
nbriggs:issue_1015_big-endian-LP64

Conversation

@nbriggs

@nbriggs nbriggs commented Apr 23, 2021

Copy link
Copy Markdown
Contributor

Reworks the conversion of bytes in little-endian order to host order to
operate independently of the sizeof(long) and the byte-order of the host system.
The extracted value is stored as uint32_t as the code already performs casts
to signed/unsigned of varying sizes as appropriate to the context of use.

Closes issue #1015

Reworks the conversion of bytes in little-endian order to host order to
operate independently of the sizeof(long) and the byte-order of the host system.
The extracted value is stored as uint32_t as the code already performs casts
to signed/unsigned of varying sizes as appropriate to the context of use.
@nbriggs

nbriggs commented Apr 23, 2021

Copy link
Copy Markdown
Contributor Author

See withdrawn/closed PR #1016 for additional discussion.

@jimklimov

Copy link
Copy Markdown
Member

Thanks, so in this incarnation, does the byte-stream-to-number conversion work reasonably for all host types and word lengths involved?

@nbriggs

nbriggs commented Apr 23, 2021

Copy link
Copy Markdown
Contributor Author

Yes, the new conversion of a little-endian number in the byte stream is independent of word size (32/64 bit) and endian-ness. It doesn't address the bug I raised in issue #1023 which will need some more thought.

@jimklimov

Copy link
Copy Markdown
Member

Just in case - is it also producing numbers as expected for shorter integers (8, 16 bits), in particular with no garbage in uninitialized memory of bytes not touched? Seems all should be OK, but better double-checked than sorry :)

@nbriggs

nbriggs commented Apr 23, 2021

Copy link
Copy Markdown
Contributor Author

Yes, there is no possibility of there being uninitialized bytes in the result as the entire result (pParser->Value) is zeroed before anything is accumulated into it, and the only values subsequently accumulated are the 0, 1, 2, or 4 bytes as specified by the length of the item.

This code is used to parse the report descriptors but not the values that the UPS reports back as its state changes (that's GetValue)

@jimklimov
jimklimov merged commit a0d8aa0 into networkupstools:master May 24, 2021
@jimklimov jimklimov added the USB-HID encoding/LogMin/LogMax/Exponent Issues and solutions (PRs) specifically about incorrect values in bitstream label Jan 12, 2022
@jimklimov jimklimov mentioned this pull request Jan 30, 2024
7 of 8 tasks
jimklimov added a commit to jimklimov/nut that referenced this pull request Dec 17, 2024
…ogMin/LogMax error origins [networkupstools#1024, networkupstools#1512, networkupstools#2718]

Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

USB-HID encoding/LogMin/LogMax/Exponent Issues and solutions (PRs) specifically about incorrect values in bitstream

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants