undefined behavior in do_fill_uninitialized_memory()
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 52/100
Hướng nghiên cứu
Bắt đầu trong boost/circular_buffer/debug.h, tại do_fill_uninitialized_memory(), và xem xét đường đi của thao tác tạo bản sao đối với một circular_buffer rỗng. Tái hiện ví dụ với GCC 9.1, -fsanitize=undefined và -DBOOST_CB_ENABLE_DEBUG=1; công việc được hoàn tất khi trường hợp sao chép rỗng không còn báo lỗi con trỏ null, trong khi các lần fill có giá trị khác không vẫn được kiểm tra.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Using gcc 9.1 with -fsanitize=undefined and -DBOOST_CB_ENABLE_DEBUG=1, the following code results in a ubsan error: "boost/circular_buffer/debug.hpp:37:16: runtime error: null pointer passed as argument 1, which is declared to never be null".
using Q = boost::circular_buffer<int>;
Q q;
const Q q2(q);
The ubsan error is a result of the following code in circular_buffer/debug.h:
template <class T>
inline void do_fill_uninitialized_memory(T* data, std::size_t size_in_bytes) BOOST_NOEXCEPT {
std::memset(static_cast<void*>(data), UNINITIALIZED, size_in_bytes);
}
During copy construction, the function gets called with data == nullptr and size_in_bytes == 0. I believe that passing a null pointer to memset is technically undefined behavior even if the size is 0.
Changing the above function as follows avoids the ubsan error:
template <class T>
inline void do_fill_uninitialized_memory(T* data, std::size_t size_in_bytes) BOOST_NOEXCEPT {
if (size_in_bytes != 0u) {
std::memset(static_cast<void*>(data), UNINITIALIZED, size_in_bytes);
}
}
I had originally written it to check for data != nullptr, but since this is debug code I thought it seemed desirable to know if the function is ever called with data == null and size_in_bytes != 0. In any case, either way will prevent the ubsan error.
- Ngôn ngữ chính
- C++
- Star
- 65
- Fork
- 64
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của boostorg/circular_buffer
-
boost/config.hpp not available Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
boostorg/circular_buffer#53 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
boostorg/circular_buffer#51 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 45/100
boostorg/circular_buffer#48 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
boostorg/circular_buffer#47 ·
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
boostorg/circular_buffer#46 · 4 bình luận ·
Tất cả issue của boostorg/circular_buffer
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
flutter-webrtc/flutter-webrtc#2206 ·
-
litertlm-android AAR ships no consumer ProGuard rules → "mid == null" SIGABRT in minified apps Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
google-ai-edge/LiteRT-LM#3739 ·
-
Component: GLib
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
Mute ydb/tests/functional/dstool/test_canonical_requests.py.Test.test_group_take_snapshot in main Đang mởai_reviewed
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
ydb-platform/ydb#53974 · 3 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
google/libultrahdr#485 ·