Summary: | dev-libs/libnop-2021.11.03 fails test - ERROR: dev-libs/libnop-2021.11.03::gentoo failed (test phase): | ||
---|---|---|---|
Product: | Gentoo Linux | Reporter: | Toralf Förster <toralf> |
Component: | Current packages | Assignee: | Tupone Alfredo <tupone> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | arsen |
Priority: | Normal | Keywords: | TESTFAILURE |
Version: | unspecified | ||
Hardware: | All | ||
OS: | Linux | ||
Whiteboard: | |||
Package list: | Runtime testing required: | --- | |
Bug Depends on: | |||
Bug Blocks: | 884417 | ||
Attachments: |
emerge-info.txt
dev-libs:libnop-2021.11.03:20231015-122340.log emerge-history.txt environment etc.clang.tar.xz etc.portage.tar.xz qlist-info.txt.xz temp.tar.xz |
Description
Toralf Förster
2023-10-15 13:32:55 UTC
Created attachment 872905 [details]
emerge-info.txt
Created attachment 872906 [details]
dev-libs:libnop-2021.11.03:20231015-122340.log
Created attachment 872907 [details]
emerge-history.txt
Created attachment 872908 [details]
environment
Created attachment 872909 [details]
etc.clang.tar.xz
Created attachment 872910 [details]
etc.portage.tar.xz
Created attachment 872911 [details]
qlist-info.txt.xz
Created attachment 872912 [details]
temp.tar.xz
tracked down to -> std::copy(&data_[index_], &data_[index_ + length_bytes], begin_byte); where data_[index_ + length_bytes] is accessing the last + 1 element but std::copy does not access it, it does copy [low..up) Can this be closed ? op[] is expressed in terms of *(begin() + idx): https://eel.is/c++draft/sequence.reqmts#119 dereferencing the end iterator is invalid. with that context: (gdb) p data_ $10 = std::vector of length 6, capacity 8 = {188 '\274', 4 '\004', 1 '\001', 2 '\002', 3 '\003', 4 '\004'} (gdb) p index_ + length_bytes $11 = 6 (gdb) this means that end() is dereferenced through op[]. the code ought to do std::copy(data_.begin() + index, data_.begin() + index_ + length_bytes, begin_byte) (that also ought to be formatted better.. auto start = data_begin() + index; and use start instead) (In reply to Arsen Arsenović from comment #10) > op[] is expressed in terms of *(begin() + idx): > https://eel.is/c++draft/sequence.reqmts#119 > > dereferencing the end iterator is invalid. I cannot say I am a c++ expert but that std:copy is equivalent to std::copy(&data_[index_], &data_.end(), begin_byte) std::copy does not dereference the 2nd parameter. I don't see why should I fix it. I know that something like std::copy(&data_[index_], &data_[index_ + length_bytes - 1] + 1, begin_byte); can work to overcome the assert but that is just a trick (In reply to Tupone Alfredo from comment #11) > I cannot say I am a c++ expert but I am though. > that std:copy is equivalent to > > std::copy(&data_[index_], &data_.end(), begin_byte) Well that won't even compile. If you mean &*data_.end() then yes, it is equivalent to that, and that's also invalid. The past-the-end iterator returned by data_.end() is not dereferenceable, so *data_.end() has undefined behaviour. > std::copy does not dereference the 2nd parameter. That's true, but the problem is not inside std::copy. The problem occurs before you even call std::copy where you access a non-existent element after the end of the container and then try to take its address. You cannot take the address of an object that doesn't exist. It's valid to add one to the address of the last object, to get a past-the-end pointer. It's not valid to access after the last object and take its address. int arr[2]; int* end = arr + 2; // OK int* bad = &arr[2]; // undefined > I don't see why should I > fix it. Because it's not valid C++. The assertion is correct, and your code is not. If you don't care to write valid C++ that's your choice, but this is your bug, not gentoo's. I applied this patch --- a/test/test_reader.h 2023-11-14 22:21:10.528641740 +0100 +++ b/test/test_reader.h 2023-11-14 22:21:23.195431970 +0100 @@ -57,7 +57,7 @@ if (length_bytes > (data_.size() - index_)) return ErrorStatus::ReadLimitReached; - std::copy(&data_[index_], &data_[index_ + length_bytes], begin_byte); + std::copy(&data_[index_], &data_[index_] + length_bytes, begin_byte); index_ += length_bytes; return {}; } I wrongly closed the parent's bug. Reopened commit d7c0d71054fd98e8105ccf7a6173aa6e42bff146 Author: Alfredo Tupone <tupone@gentoo.org> Date: Tue Nov 14 22:26:52 2023 +0100 dev-libs/libnop: Failures with -D_GLIBCXX_ASSERTIONS Closes: https://bugs.gentoo.org/884417 Signed-off-by: Alfredo Tupone <tupone@gentoo.org> i.e. https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=d7c0d71054fd98e8105ccf7a6173aa6e42bff146 |