Unsigned integer axis maps below-range values to overflow
Đá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
- 76/100
Hướng nghiên cứu
Đọc include/boost/histogram/axis/integer.hpp quanh dòng 109 và hợp đồng chỉ mục Axis trong doc/concepts/Axis.qbk. Bắt đầu bằng cách chạy repro.cpp với các header được ghim phiên bản và các lệnh build C++17 được cung cấp; sau đó kiểm tra phép trừ không dấu tạo ra chỉ mục được báo cáo. Công việc hoàn tất khi đầu vào dưới phạm vi trả về -1 và tăng underflow, trong khi các chỉ mục được liệt kê nằm trong và trên phạm vi vẫn như mong đợi.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
axis::integer<unsigned>(1, 4) maps 0u to overflow. The Axis contract requires underflow for this below-range value.
Reproduced on x86-64 Ubuntu 24.04 with GCC 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04.1) and Clang 18.1.3 (Ubuntu 1ubuntu1). The examples use C++17 Release builds with -O2, without fast-math. Supplemental verifier controls also used -DNDEBUG.
Tested Boost.Histogram commit: 22740e5082ca99d5717da8d9c31d684be9aaeecf. Dependency headers came from Boost superproject commit afa7af297165ad85978b364eb9df19e098109d9e, whose Histogram gitlink matches that pin.
Master still equals the tested commit as checked on 2026-10-12. Default develop at f9017f94684583eeef80eb230768c932a8a6e76c retains the cited expressions. Develop was read, not tested.
From a fresh directory, prepare the pinned sources:
git clone https://github.com/boostorg/histogram.git histogram
git -C histogram checkout --detach 22740e5082ca99d5717da8d9c31d684be9aaeecf
git clone --no-checkout https://github.com/boostorg/boost.git boost
git -C boost checkout --detach afa7af297165ad85978b364eb9df19e098109d9e
git -C boost submodule update --init --jobs 3 \
libs/config libs/core libs/mp11 libs/throw_exception libs/variant2 libs/assert
Save this example as repro.cpp:
#include <boost/histogram.hpp>
#include <iostream>
int main() {
namespace bh = boost::histogram;
auto h = bh::make_histogram(bh::axis::integer<unsigned>(1, 4));
h(0u);
const auto index = h.axis().index(0u);
std::cout << "index(0)=" << index << " underflow=" << h.at(-1)
<< " overflow=" << h.at(3) << '\n';
return index == -1 && h.at(-1) == 1 && h.at(3) == 0 ? 0 : 1;
}
Run these commands in Bash with g++ and clang++-18 on PATH:
includes=(-I"$PWD/histogram/include")
for module in config core mp11 throw_exception variant2 assert; do
includes+=(-I"$PWD/boost/libs/$module/include")
done
for cxx in g++ clang++-18; do
"$cxx" -std=c++17 -O2 -Wall -Wextra "${includes[@]}" \
repro.cpp -o "repro-$cxx"
"./repro-$cxx"
printf 'exit=%s\n' "$?"
done
Both compiler runs print the observed result below and exit 1 because the expected-value check fails.
The Axis index contract assigns -1 to values below the covered range and size() to values above it. The integer axis interface permits integral value types and defines the interval as [start, stop).
Expected for the single fill: index(0u) == -1, underflow 1, overflow 0, and all three ordinary bins 0. Observed:
index(0)=3 underflow=0 overflow=1
For inputs 0u, 1u, 2u, 3u, 4u, 5u, expected indices are -1,0,1,2,3,3. Observed indices are 3,0,1,2,3,3. The independent Python integer oracle also gives flow-inclusive counts 1,1,1,1,2, compared with observed 0,1,1,1,3.
At integer.hpp:109, x - min_ is evaluated in the unsigned value type before conversion to double. For 0u - 1u, the defined unsigned wrap produces a large positive value that selects overflow.
Issue 437, item 7, discusses extreme signed arithmetic at this same source line. The example here uses small unsigned values.
The verifier checked all values from 0 through 5 on the shifted unsigned axis. A signed axis on [1,4) and an unsigned axis on [0,4) give the required indices and counts. These checks cover the small programs and listed controls. The full library test suite, other compilers, other platforms, and C++14/C++20 builds were not run.
The reproduction example is provided under CC0.
Found by ChipLab's AI verification agents and independently reproduced.
ChipLab ref: CLAB-2026-929
- Ngôn ngữ chính
- C++
- Star
- 334
- Fork
- 76
- Merge trung bình
- 6 ngày 13 giờ
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
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/histogram
-
Fable review of Boost.HistogramĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 28/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
axes should provide strong exception guarantee for metadataCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
Tất cả issue của boostorg/histogram
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
llvm/offload-test-suite#1703 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
BGI-shenzhen/PopLDdecay#25 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 68/100
eic/TimeframeBuilder#102 ·