| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
std::fill_n and std::generate_n do nothing when the count is zero or negative. The parallel versions converted the count straight to size_t, so a negative count became a huge element count and, with more than one worker, the tasks wrote past the end of the range. Clamp the count to zero before converting it, and add tests for counts of 0, -1 and -1000 with 1 to 4 workers and each partitioner.
| Back | FazBrowse Home | New Git URL |
fill_n and generate_n are documented as std::fill_n / std::generate_n in parallel. The std versions do nothing when the count is zero or negative, but make_fill_n_task and make_generate_n_task convert the count with size_t N = count;, so a count of -1 becomes SIZE_MAX. With one worker the task falls back to std::fill_n / std::generate_n and nothing happens. With more workers the range is split as if it held SIZE_MAX elements and the tasks write past the end of the container.
Reproduction on master (bbd7251):
I ran this with 1 to 4 workers for both fill_n and generate_n. With 1 worker it returns with vec unchanged. With 2, 3 or 4 workers it crashed in all 60 runs (10 per case). With this change all eight cases return with vec unchanged.
Changes
Full ctest (GCC 13.3, Release): 3047/3047 pass, against 3045/3045 on master.