Skip to content

Conversation

@andrewboie
Copy link
Contributor

Casting the rb_data character array to a u32_t can result
in an unaligned u32_t * pointer being passed to
ring_buf_item_put(), since rb_data is only byte-aligned.

Our Altera Max10 CPU build is not configured to detect
unaligned memory access and throw an exception, it is
instead rounding down the memory address
of the data pointer to the nearest 4-byte value, causing
the wrong data to be copied into the ring buffer.

It appears that in the C standard this is considered
Undefined Behavior so the approach this patch takes is
to fix the test, by ensuring that rb_data is aligned to
u32_t.

Fixes: #14869

Signed-off-by: Andrew Boie andrew.p.boie@intel.com

Casting the rb_data character array to a u32_t can result
in an unaligned u32_t * pointer being passed to
ring_buf_item_put(), since rb_data is only byte-aligned.

Our Altera Max10 CPU build is not configured to detect
unaligned memory access and throw an exception, it is
instead rounding down the memory address
of the data pointer to the nearest 4-byte value, causing
the wrong data to be copied into the ring buffer.

It appears that in the C standard this is considered
Undefined Behavior so the approach this patch takes is
to fix the test, by ensuring that rb_data is aligned to
u32_t.

Fixes: zephyrproject-rtos#14869

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
@andrewboie andrewboie requested review from a user, andyross, ceolin, dcpleung and nashif April 9, 2019 22:28
@andrewboie andrewboie added the bug The issue is a bug, or the PR is fixing a bug label Apr 9, 2019
@andrewboie andrewboie added this to the v1.14.0 milestone Apr 9, 2019
@nashif nashif merged commit 9926f94 into zephyrproject-rtos:master Apr 9, 2019
@arun1joshi
Copy link
Contributor

verified that the tests/lib/ringbuffer test cases are passed with the latest commit 9926f94

@andrewboie andrewboie deleted the nios2-fix-rb-test branch April 10, 2019 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug The issue is a bug, or the PR is fixing a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tests/lib/ringbuffer: Assertion failure at test_ring_buffer_main()

4 participants