ITADN

printf: arithmetic overflow (overflow-checks) on a `%*d` dynamic field width of `i64::MIN`

#13766Openleeewee 创建于 24 天前
U - printfgood first issue
L
leeeweecommented
printf's `%*` dynamic field width takes the width from an argument (`printf '%*d' <width> <value>`). For a **negative** width, `resolve_asterisk_width` computes `-(nb as isize)` to get the magnitude. https://github.com/uutils/coreutils/blob/21d4e9635b07a04f262cd8a5386f2987bca6cfef/src/uucore/src/lib/features/format/spec.rs#L505-L521 When the width argument is `i64::MIN` (`-9223372036854775808`), `nb as isize` is `isize::MIN`, and negating it **overflows** (it has no positive counterpart), panicking with `attempt to negate with overflow` under `-C overflow-checks` (exit 134). ```console $ printf '%*d' -9223372036854775808 1 thread 'main' panicked at src/uucore/src/lib/features/format/spec.rs:520:39: attempt to negate with overflow $ echo $? 134 ```
1 条评论