When 900 or more jobs all have different states it is possible for the
space required to display the ETA line to be larger than the ETA output
buffer. fio initially truncates what it puts in the output buffer but
incorrectly advances where it thinks the end of the buffer is - when
truncating snprintf returns the number of characters that _would_ have
been converted if there had been enough space...
This patch fixes the post truncation calculation and adjusts the "left"
variable so there is room for the carriage return and a null terminator.
The following script reproduces the problem when fio has been compiled
with -fstack-protector or -fsanitize=address:
rw[0]='read'; rw[1]='write'; \
for i in {1..1000}; do \
echo -e "[job$i]\nrw=${rw[$((i % 2))]}\n" \
"ramp_time=$(((1000 - i) / 350 * 5))\n" \
"runtime=$((60 - (i % 3) * 2))"; \
done | \
./fio --eta-newline=1s --group_reporting --ioengine=null --size=1g \
--time_based --bs=512 --thread --rate_iops=123456 -
Fixes: https://github.com/axboe/fio/issues/500 ("Large number of threads
result in Seg faults") Signed-off-by: Sitsofe Wheeler <sitsofe@yahoo.com>