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

test_intrusive_list.cpp fails to compile (-Werror=array-bounds) due to subscript -1 is out of bounds #649

Closed
janhenke opened this issue Dec 25, 2022 · 7 comments
Assignees
Labels

Comments

@janhenke
Copy link

janhenke commented Dec 25, 2022

[133/288] /usr/bin/x86_64-pc-linux-gnu-g++ -DETL_DEBUG -I/var/tmp/portage/dev-embedded/etlcpp-20.35.8/work/etl-20.35.8/test/../include -isystem /var/tmp/portage/dev-embedded/etlcpp-20.35.8/work/etl-20.35.8/test/UnitTest++/..  -march=native -O2 -pipe -fsanitize=address,undefined -Wall -Wextra -Werror -std=gnu++17 -MD -MT test/CMakeFiles/etl_tests.dir/test_intrusive_list.cpp.o -MF test/CMakeFiles/etl_tests.dir/test_intrusive_list.cpp.o.d -o test/CMakeFiles/etl_tests.dir/test_intrusive_list.cpp.o -c /var/tmp/portage/dev-embedded/etlcpp-20.35.8/work/etl-20.35.8/test/test_intrusive_list.cpp
FAILED: test/CMakeFiles/etl_tests.dir/test_intrusive_list.cpp.o 
/usr/bin/x86_64-pc-linux-gnu-g++ -DETL_DEBUG -I/var/tmp/portage/dev-embedded/etlcpp-20.35.8/work/etl-20.35.8/test/../include -isystem /var/tmp/portage/dev-embedded/etlcpp-20.35.8/work/etl-20.35.8/test/UnitTest++/..  -march=native -O2 -pipe -fsanitize=address,undefined -Wall -Wextra -Werror -std=gnu++17 -MD -MT test/CMakeFiles/etl_tests.dir/test_intrusive_list.cpp.o -MF test/CMakeFiles/etl_tests.dir/test_intrusive_list.cpp.o.d -o test/CMakeFiles/etl_tests.dir/test_intrusive_list.cpp.o -c /var/tmp/portage/dev-embedded/etlcpp-20.35.8/work/etl-20.35.8/test/test_intrusive_list.cpp
In file included from /var/tmp/portage/dev-embedded/etlcpp-20.35.8/work/etl-20.35.8/test/test_intrusive_list.cpp:33:
/var/tmp/portage/dev-embedded/etlcpp-20.35.8/work/etl-20.35.8/test/../include/etl/intrusive_list.h: In function ‘void UnitTest::ExecuteTest(T&, const UnitTest::TestDetails&, bool) [with T = {anonymous}::Suitetest_intrusive_list::SetupFixturetest_sort_compareHelper]’:
/var/tmp/portage/dev-embedded/etlcpp-20.35.8/work/etl-20.35.8/test/../include/etl/intrusive_list.h:617:68: error: array subscript -1 is outside array bounds of ‘{anonymous}::DataNDC1 [1]’ {aka ‘etl::intrusive_list<{anonymous}::ItemNDCNode, etl::bidirectional_link<1> > [1]’} [-Werror=array-bounds]
  617 |       return iterator(static_cast<value_type&>(this->terminal_link));
      |                                                                    ^
/var/tmp/portage/dev-embedded/etlcpp-20.35.8/work/etl-20.35.8/test/test_intrusive_list.cpp:819:16: note: while referencing ‘data1’
  819 |       DataNDC1 data1(unsorted_data.begin(), unsorted_data.end());
      |                ^~~~~

While packaging this for Gentoo, I enabled the test suite. Unfortunately the tests do not compile with the above error. Can someone with more insight into the test suite take a look at this? Compiler is gcc (Gentoo 11.3.1_p20221209 p3) 11.3.1 20221209.

Please note that this error repeats several times for the file, I copied just the first occurrence.

@jwellbelove
Copy link
Contributor

I think it may be due to that fact that iterators in intrusive_list are constructed from references to nodes and end() finds a reference to the terminal_node. terminal_node does not point to a valid element and, although it is not referenced, it may be upsetting the sanitizer.

Changing the iterator constructor to take a pointer rather than a reference is simple.
I've attached an updated file for you to try.
intrusive_list.h.txt

@jwellbelove jwellbelove moved this from To do to In progress in Embedded Template Library Dec 28, 2022
@jwellbelove
Copy link
Contributor

Were you able to try the fix?

@janhenke
Copy link
Author

Unfortunately these changes did not fix the issue. Build log with the above file: https://gitlab.com/-/snippets/2489763/raw

@jwellbelove
Copy link
Contributor

My experiments so far show that the issue is down to the value_type multiple inheriting from two link_type base classes. The error occurs when the value_type is up-cast from one of the base types.

@jwellbelove
Copy link
Contributor

Currently, the test node is define as follows.

typedef etl::bidirectional_link<0> FirstLink;
typedef etl::bidirectional_link<1> SecondLink;

class ItemDCNode : public FirstLink, public SecondLink

If the tests are modified so that it is defined as below, then the error disappears.
class ItemDCNode : public FirstLink

@jwellbelove
Copy link
Contributor

I've found the issue.
To resolve it I had to change the code to work with link_type pointers and only cast the value_type pointers when I needed to access the actual value.
The underlying issue was that terminal_link, which is a link_type pointer, was being cast to value_type pointer.

jwellbelove added a commit that referenced this issue Mar 1, 2023
…ds-test-failure

# Conflicts:
#	include/etl/intrusive_forward_list.h
#	include/etl/intrusive_list.h
#	include/etl/optional.h
#	test/test_optional.cpp
#	test/vs2019/etl.vcxproj.filters
@jwellbelove
Copy link
Contributor

Fixed in 20.35.13

@github-project-automation github-project-automation bot moved this from In progress to Done in Embedded Template Library Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

No branches or pull requests

2 participants