-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Reading 8- or 16-bit attributes from big-endian device returns 0 (#6166) #6175
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,6 +88,37 @@ typedef void (*EmberAfGenericClusterFunction)(void); | |
*/ | ||
#define EMBER_AF_NULL_MANUFACTURER_CODE 0x0000 | ||
|
||
/** | ||
* @brief Type for align a 16 bits value. | ||
* | ||
* This structure has the same size as a pointer and is used to align | ||
* a 16 bit value to the 16 least significant bits of a pointer. | ||
* Note that this structure is aware of the endianess and the pointer size. | ||
*/ | ||
typedef struct | ||
{ | ||
#if defined(BIGENDIAN_CPU) && (BIGENDIAN_CPU != 0) | ||
// Big endian | ||
#if (UINTPTR_MAX == UINT32_MAX) | ||
uint32_t align : 16; | ||
uint16_t value; | ||
#elif (UINTPTR_MAX == UINT64_MAX) | ||
uint64_t align : 48; | ||
uint16_t value; | ||
#endif | ||
#else | ||
// Little endian | ||
#if (UINTPTR_MAX == UINT32_MAX) | ||
uint16_t value; | ||
uint32_t align : 16; | ||
#elif (UINTPTR_MAX == UINT64_MAX) | ||
uint16_t value; | ||
uint64_t align : 48; | ||
#endif | ||
|
||
#endif // defined(BIGENDIAN_CPU) && (BIGENDIAN_CPU != 0) | ||
} EmberAfAlignValue16; | ||
|
||
/** | ||
* @brief Type for default values. | ||
* | ||
|
@@ -106,7 +137,7 @@ typedef union | |
/** | ||
* Actual default value if the attribute size is 2 bytes or less. | ||
*/ | ||
uint16_t defaultValue; | ||
EmberAfAlignValue16 defaultValue; | ||
} EmberAfDefaultAttributeValue; | ||
|
||
/** | ||
|
@@ -143,9 +174,9 @@ typedef union | |
*/ | ||
uint8_t * ptrToDefaultValue; | ||
/** | ||
* Actual default value if the attribute size is 2 bytes or less. | ||
* Default value of the attribute. | ||
Comment on lines
-146
to
+177
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change to the comment? The new comment does not seem to be correct if the attribute type is larger than 2-byte; in that case this field is not really the default value in any sense; the |
||
*/ | ||
uint16_t defaultValue; | ||
EmberAfAlignValue16 defaultValue; | ||
/** | ||
* Points to the min max attribute value structure, if min/max is | ||
* supported for this attribute. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be making assumptions about how a bitfield and an integer will pack that might not be valid in practice.... Nothing I'm aware of requires them to pack with no gaps here.
At the very least we should static_assert that
sizeof(EmberAfAlignValue16) == sizeof(uint8_t*)
, right? That way we will catch it if things pack wrong.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.