vim-patch:98a0cbf: patch 9.1.1971: crash with invalid positional argument 0 in printf() (#36919)

Problem:  crash with invalid positional argument 0 in printf()
Solution: Reject positional arguments <= 0.

closes: vim/vim#18898

98a0cbf05b

Co-authored-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq
2025-12-12 08:14:58 +08:00
parent cfb586a77b
commit a66fce6fab
5 changed files with 25 additions and 18 deletions

View File

@@ -6744,24 +6744,24 @@ function vim.fn.prevnonblank(lnum) end
--- <
--- *E1502*
--- You can re-use a [field-width] (or [precision]) argument: >vim
--- echo printf("%1$d at width %2$d is: %01$*2$d", 1, 2)
--- echo printf("%1$d at width %2$d is: %1$0*2$d", 1, 2)
--- " 1 at width 2 is: 01
--- <
--- However, you can't use it as a different type: >vim
--- echo printf("%1$d at width %2$ld is: %01$*2$d", 1, 2)
--- echo printf("%1$d at width %2$ld is: %1$0*2$d", 1, 2)
--- " E1502: Positional argument 2 used as field width reused as
--- " different type: long int/int
--- <
--- *E1503*
--- When a positional argument is used, but not the correct number
--- or arguments is given, an error is raised: >vim
--- echo printf("%1$d at width %2$d is: %01$*2$.*3$d", 1, 2)
--- echo printf("%1$d at width %2$d is: %1$0*2$.*3$d", 1, 2)
--- " E1503: Positional argument 3 out of bounds: %1$d at width
--- " %2$d is: %01$*2$.*3$d
--- " %2$d is: %1$0*2$.*3$d
--- <
--- Only the first error is reported: >vim
--- echo printf("%01$*2$.*3$d %4$d", 1, 2)
--- " E1503: Positional argument 3 out of bounds: %01$*2$.*3$d
--- echo printf("%1$0*2$.*3$d %4$d", 1, 2)
--- " E1503: Positional argument 3 out of bounds: %1$0*2$.*3$d
--- " %4$d
--- <
--- *E1504*