binutils-gdb/gdb/unittests
Simon Marchi 610cfd618e Compare iterators, not values, in filtered_iterator::operator{==,!=}
The == and != operators on filtered_iterator are not doing the
right thing, they compare values pointed by the wrapped iterators
instead of comparing the iterators themselves.

As a result, operator== will return true if the two iterators point to
two equal values at different positions.  operator!= will fail
similarly.

Also, this causes it to deference past-the-end iterators when doing.
For example, in

  for (iter = ...; iter != end_iter; ++iter)

the != comparison dereferences end_iter.  I don't think this should
happen.

I don't think it's a problem today, given that we only use
filtered_iterator to wrap linked lists of threads and inferiors.
Dereferencing past-the-end iterators of these types is not fatal, it
just returns NULL, which is not a value we otherwise find in the lists.
But in other contexts, it could become problematic.

I have added a simple self test that fails without the fix applied.

gdb/ChangeLog:

	* filtered-iterator.h (filtered_iterator) <operator==,
	operator!=>: Compare wrapped iterators, not wrapped pointers.
	* Makefile.in (SUBDIR_UNITTESTS_SRCS): Add
	unittests/filtered_iterator-selftests.c.
	* unittests/filtered_iterator-selftests.c: New file.
2019-12-04 13:27:56 -05:00
..
basic_string_view Make functions static in unittests 2019-11-26 14:29:20 -05:00
optional Make functions static in unittests 2019-11-26 14:29:20 -05:00
array-view-selftests.c Make functions static in unittests 2019-11-26 14:29:20 -05:00
child-path-selftests.c
cli-utils-selftests.c
common-utils-selftests.c
copy_bitwise-selftests.c
environ-selftests.c
filtered_iterator-selftests.c Compare iterators, not values, in filtered_iterator::operator{==,!=} 2019-12-04 13:27:56 -05:00
format_pieces-selftests.c Handle %I64d in format_pieces 2019-11-21 14:39:40 -07:00
function-view-selftests.c
help-doc-selftests.c
lookup_name_info-selftests.c
main-thread-selftests.c Introduce run_on_main_thread 2019-11-26 14:02:57 -07:00
memory-map-selftests.c
memrange-selftests.c
mkdir-recursive-selftests.c
observable-selftests.c
offset-type-selftests.c
optional-selftests.c
parse-connection-spec-selftests.c
ptid-selftests.c
rsp-low-selftests.c [gdb] Fix more typos in comments (2) 2019-10-26 09:55:32 +02:00
scoped_fd-selftests.c
scoped_mmap-selftests.c
scoped_restore-selftests.c
string_view-selftests.c
style-selftests.c
tracepoint-selftests.c
tui-selftests.c Fix another build failure in tui-selftests.c 2019-12-04 08:08:13 -07:00
unpack-selftests.c
utils-selftests.c
vec-utils-selftests.c gdb: fix build error in unittests/vec-utils-selftests.c 2019-11-14 06:51:30 -05:00
xml-utils-selftests.c