[vim/vim] Format positional arguments (PR #12140)

62 views
Skip to first unread message

cvwillegen

unread,
Mar 11, 2023, 10:37:11 AM3/11/23
to vim/vim, Subscribed

This PR adds the possibility to use positional arguments in the printf() function, and in translation files, opening the possibility for translators to specify word order in translations.

Ex: echo printf("My name is %2$s, %1$s", "Bram", "Moolenaar")

echo printf("My date of birth is: %03$*1$d/%04$*1$d/%05$*2$d", 2, 4, 13, 7, 2002)


You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/12140

Commit Summary

  • 8faa037 Support positional arguments in string formatting
  • c4abeda Try to fix build errors.
  • 7ecd3aa Move type strings to globals.h
  • 0ce79fb Fix message declarations
  • a27ec4d Fix GCC warnings about invalid format strings
  • 710a0ba Fix tab/space mixup.
  • 692612b Merge branch 'vim:master' into format-positional-arguments

File Changes

(8 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140@github.com>

cvwillegen

unread,
Mar 11, 2023, 10:42:23 AM3/11/23
to vim/vim, Subscribed

Fixes #10577


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/c1464938662@github.com>

cvwillegen

unread,
Mar 12, 2023, 7:38:07 AM3/12/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • 08c9923 Merge branch 'vim:master' into format-positional-arguments


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/12911848851@github.com>

codecov[bot]

unread,
Mar 12, 2023, 6:28:07 PM3/12/23
to vim/vim, Subscribed

Codecov Report

Merging #12140 (08c9923) into master (d13dd30) will decrease coverage by 81.57%.
The diff coverage is 45.50%.

@@             Coverage Diff             @@
##           master   #12140       +/-   ##
===========================================
- Coverage   81.94%    0.38%   -81.57%     
===========================================
  Files         164      154       -10     
  Lines      194094   179629    -14465     
  Branches    43829    41033     -2796     
===========================================
- Hits       159056      685   -158371     
- Misses      22204   178853   +156649     
+ Partials    12834       91    -12743     
Flag Coverage Δ
huge-clang-none ?
huge-gcc-none ?
huge-gcc-testgui ?
huge-gcc-unittests 0.38% <45.50%> (+0.09%) ⬆️
linux 0.38% <45.50%> (-82.00%) ⬇️
mingw-x64-HUGE ?
mingw-x86-HUGE ?
windows ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/strings.c 23.50% <43.18%> (-69.26%) ⬇️
src/message_test.c 100.00% <100.00%> (ø)

... and 157 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/c1465316761@github.com>

cvwillegen

unread,
Mar 13, 2023, 2:43:25 PM3/13/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • 364fcbc Merge branch 'vim:master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/12926730317@github.com>

cvwillegen

unread,
Mar 14, 2023, 4:07:32 PM3/14/23
to vim/vim, Push

@cvwillegen pushed 2 commits.

  • 8a6a008 Improve test coverage, fix uncovered errors.
  • f960924 Merge branch 'format-positional-arguments' of github.com:cvwillegen/vim into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/12942495714@github.com>

cvwillegen

unread,
Mar 16, 2023, 9:57:10 AM3/16/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • 14fc41e Merge branch 'vim:master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/12967018594@github.com>

cvwillegen

unread,
Mar 17, 2023, 8:45:55 AM3/17/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • 40c0e7d Merge branch 'vim:master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/12979925552@github.com>

cvwillegen

unread,
Mar 17, 2023, 8:47:42 AM3/17/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • 03d9209 Give E767 for positional printf() call w/ too many params

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/12979946986@github.com>

cvwillegen

unread,
Mar 18, 2023, 6:01:12 PM3/18/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • a0aa99a Merge branch 'vim:master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/12991874072@github.com>

cvwillegen

unread,
Mar 20, 2023, 4:42:18 AM3/20/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • bc5b502 Fix order of flags and positional arguments.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/13001937214@github.com>

cvwillegen

unread,
Mar 20, 2023, 4:52:28 AM3/20/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • 75d00c9 Merge branch 'vim:master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/13002045365@github.com>

cvwillegen

unread,
Mar 20, 2023, 4:53:05 AM3/20/23
to vim/vim, Push

@cvwillegen pushed 2 commits.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/13002051918@github.com>

cvwillegen

unread,
Mar 20, 2023, 5:51:32 PM3/20/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • 1ecf570 Merge branch 'vim:master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/13011426726@github.com>

cvwillegen

unread,
Mar 22, 2023, 9:16:41 AM3/22/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • 9d7520b Merge branch 'vim:master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/13033593805@github.com>

cvwillegen

unread,
Mar 24, 2023, 7:26:54 AM3/24/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • 0750e4b Merge branch 'vim:master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/13060548799@github.com>

cvwillegen

unread,
Mar 24, 2023, 7:28:14 AM3/24/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • 4f8b44d Improve test coverage, check error message paths.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/13060562374@github.com>

cvwillegen

unread,
Mar 25, 2023, 3:07:34 AM3/25/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • 7c01be0 Merge branch 'vim:master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/13069705616@github.com>

Christ van Willegen

unread,
Mar 25, 2023, 5:37:02 PM3/25/23
to vim...@googlegroups.com, nor...@github.com
I think this one is ready for review. 

Christ van Willegen

cvwillegen

unread,
Mar 27, 2023, 9:51:59 AM3/27/23
to vim/vim, Push

@cvwillegen pushed 4 commits.

  • 1f76138 patch 9.0.1427: warning for uninitialized variable
  • c174c2e patch 9.0.1428: cursor in wrong position when leaving insert mode
  • 1a08a3e patch 9.0.1429: invalid memory access when ending insert mode
  • 67123a5 Merge branch 'vim:master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/13087545761@github.com>

cvwillegen

unread,
Mar 27, 2023, 9:53:16 AM3/27/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/13087568429@github.com>

cvwillegen

unread,
Apr 2, 2023, 8:24:19 AM4/2/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • ba410d7 Merge branch 'vim:master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/13159950517@github.com>

cvwillegen

unread,
Apr 10, 2023, 8:07:54 AM4/10/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • f5bb2fd Merge branch 'vim:master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/13245135770@github.com>

cvwillegen

unread,
Apr 17, 2023, 3:35:30 AM4/17/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • 2360c42 Merge branch 'vim:master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/13322518189@github.com>

cvwillegen

unread,
Apr 23, 2023, 5:05:05 AM4/23/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • dc9947d Merge branch 'master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/13394719906@github.com>

cvwillegen

unread,
May 5, 2023, 5:28:42 AM5/5/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • d887a19 Merge branch 'vim:master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/13533585671@github.com>

cvwillegen

unread,
May 22, 2023, 4:25:04 AM5/22/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • abad145 Merge branch 'vim:master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/13713327100@github.com>

cvwillegen

unread,
May 22, 2023, 5:23:05 AM5/22/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/13714059458@github.com>

cvwillegen

unread,
May 23, 2023, 1:07:17 PM5/23/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • 0b78545 Merge branch 'vim:master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/13734393533@github.com>

Restorer

unread,
May 23, 2023, 3:21:27 PM5/23/23
to vim/vim, Subscribed

This PR adds the possibility to use positional arguments in the printf() function, and in translation files, opening the possibility for translators to specify word order in translations.

@cvwillegen
If I understood you correctly, then the built-in gettext tools can control the order of arguments during translation.
Described here in this section of the gettext documentation.


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/c1560003344@github.com>

cvwillegen

unread,
May 23, 2023, 3:56:58 PM5/23/23
to vim/vim, Subscribed

Hi,


On Tue, May 23, 2023 at 9:21 PM Restorer ***@***.***> wrote:
> @cvwillegen
> If I understood you correctly, then the built-in gettext tools can control the order of arguments during translation.
> Described here in this section of the gettext documentation.

Yes, that is the way to specify it in the .po files, but the Vim
runtime needs to be able to format strings that are written that way,
and it wasn't (isn't) able to. This PR adds that functionality so that
translators are more free to translate to correct word order.

Christ van Willegen


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/c1560042673@github.com>

Restorer

unread,
May 23, 2023, 5:05:41 PM5/23/23
to vim/vim, Subscribed

@cvwillegen
That is, directly in the script files? Did I understand correctly?
If so, then Bram somehow promises to think about how to do this for third‐party scripts #11637 .
And for those distributed with Vim, he has already made a built‐in gettext() function and, accordingly, available mechanisms for PO files can be used for them.
But if you succeed in doing what you are doing, then it will be great.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/c1560122560@github.com>

cvwillegen

unread,
May 26, 2023, 6:26:38 AM5/26/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • faf701f Merge branch 'vim:master' into format-positional-arguments


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/13771073627@github.com>

Yegappan Lakshmanan

unread,
Aug 11, 2023, 11:04:55 AM8/11/23
to vim/vim, Subscribed

Can you please update and rebase this PR to the latest?


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/c1674936187@github.com>

cvwillegen

unread,
Aug 11, 2023, 11:12:15 AM8/11/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • cd002b4 Merge branch 'vim:master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/14645731161@github.com>

cvwillegen

unread,
Aug 11, 2023, 11:14:43 AM8/11/23
to vim/vim, Subscribed

Op vr 11 aug. 2023 17:04 schreef Yegappan Lakshmanan <
***@***.***>:


> Can you please update and rebase this PR to the latest?
>

I updated the branch.

Christ

>


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/c1674952449@github.com>

Christian Brabandt

unread,
Aug 11, 2023, 5:02:37 PM8/11/23
to vim/vim, Subscribed

can someone please try this out?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/c1675399173@github.com>

cvwillegen

unread,
Aug 11, 2023, 5:50:48 PM8/11/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • 9d3ea28 Merge branch 'vim:master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/14649338509@github.com>

cvwillegen

unread,
Aug 12, 2023, 5:59:34 AM8/12/23
to vim/vim, Push

@cvwillegen pushed 1 commit.

  • 8eace5c Merge branch 'vim:master' into format-positional-arguments

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/push/14652362596@github.com>

Christian Brabandt

unread,
Aug 13, 2023, 12:10:07 PM8/13/23
to vim/vim, Subscribed

Closed #12140 via 0c6181f.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/issue_event/10080166091@github.com>

Restorer

unread,
Aug 13, 2023, 4:04:27 PM8/13/23
to vim/vim, Subscribed

@RestorerZ commented on this pull request.


In src/globals.h:

> @@ -1674,6 +1674,19 @@ EXTERN int	cmdwin_result INIT(= 0); // result of cmdline window or 0
 
 EXTERN char_u no_lines_msg[]	INIT(= N_("--No lines in buffer--"));
 
+EXTERN char typename_unknown[]	INIT(= N_("unknown"));
+EXTERN char typename_int[]	INIT(= N_("int"));
+EXTERN char typename_longint[]	INIT(= N_("long int"));
+EXTERN char typename_longlongint[]	INIT(= N_("long long int"));
+EXTERN char typename_unsignedint[]	INIT(= N_("unsigned int"));

I'm not sure if the format specifier type needs to be translated in the error message. Types of the C language are most often written int, long, etc.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/review/1575885787@github.com>

Christian Brabandt

unread,
Aug 14, 2023, 3:52:23 AM8/14/23
to vim/vim, Subscribed

@cvwillegen
This PR introduced 2 warnings in Coverity. Can you please have a look at it:

Hi,

Please find the latest report on new defect(s) introduced to vim found with Coverity Scan.

2 new defect(s) introduced to vim found with Coverity Scan.


New defect(s) Reported-by: Coverity Scan
Showing 2 of 2 defect(s)


** CID 1539915:  API usage errors  (VARARGS)
/src/strings.c: 2881 in skip_to_arg()


________________________________________________________________________________________________________
*** CID 1539915:  API usage errors  (VARARGS)
/src/strings.c: 2881 in skip_to_arg()
2875         // Because we know that after we return from this call,
2876         // a va_arg() call is made, we can pre-emptively
2877         // increment the current argument index.
2878         ++*arg_cur;
2879         ++*arg_idx;
2880     

                CID 1539915:  API usage errors  (VARARGS)
                "va_end" was not called for "*ap".

2881         return;
2882     }
2883     
2884         int
2885     vim_vsnprintf_typval(
2886         char    *str,

** CID 1539914:    (FORWARD_NULL)


________________________________________________________________________________________________________
*** CID 1539914:    (FORWARD_NULL)
/src/strings.c: 3309 in vim_vsnprintf_typval()
3303                 // signed
3304                 switch (length_modifier)
3305                 {
3306                 case '\0':
3307                 case 'h':
3308                     // char and short arguments are passed as int.

                CID 1539914:    (FORWARD_NULL)
                Passing null pointer "ap_types" to "skip_to_arg", which dereferences it.

3309                     int_arg =
3310     # if defined(FEAT_EVAL)
3311                         tvs != NULL ? tv_nr(tvs, &arg_idx) :
3312     # endif
3313                             (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, &arg_cur),
3314                             va_arg(ap, int));
/src/strings.c: 3583 in vim_vsnprintf_typval()
3577                 double    f;
3578                 double    abs_f;
3579                 char    format[40];
3580                 int        l;
3581                 int        remove_trailing_zeroes = FALSE;
3582     

                CID 1539914:    (FORWARD_NULL)
                Passing null pointer "ap_types" to "skip_to_arg", which dereferences it.

3583                 f =
3584     # if defined(FEAT_EVAL)
3585                 tvs != NULL ? tv_float(tvs, &arg_idx) :
3586     # endif
3587                     (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, &arg_cur),
3588                     va_arg(ap, double));
/src/strings.c: 3290 in vim_vsnprintf_typval()
3284     
3285                 if (ptr_arg != NULL)
3286                     arg_sign = 1;
3287                 }
3288                 else if (fmt_spec == 'b' || fmt_spec == 'B')
3289                 {

                CID 1539914:    (FORWARD_NULL)
                Passing null pointer "ap_types" to "skip_to_arg", which dereferences it.

3290                 bin_arg =
3291     # if defined(FEAT_EVAL)
3292                         tvs != NULL ?
3293                            (uvarnumber_T)tv_nr(tvs, &arg_idx) :
3294     # endif
3295                         (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, &arg_cur),
/src/strings.c: 3166 in vim_vsnprintf_typval()
3160                 break;
3161     
3162             case 'c':
3163                 {
3164                 int j;
3165     

                CID 1539914:    (FORWARD_NULL)
                Passing null pointer "ap_types" to "skip_to_arg", which dereferences it.

3166                 j =
3167     # if defined(FEAT_EVAL)
3168                     tvs != NULL ? tv_nr(tvs, &arg_idx) :
3169     # endif
3170                     (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, &arg_cur),
3171                     va_arg(ap, int));
/src/strings.c: 3277 in vim_vsnprintf_typval()
3271                 // conversion
3272                 void *ptr_arg = NULL;
3273     
3274                 if (fmt_spec == 'p')
3275                 {
3276                 length_modifier = '\0';

                CID 1539914:    (FORWARD_NULL)
                Passing null pointer "ap_types" to "skip_to_arg", which dereferences it.

3277                 ptr_arg =
3278     # if defined(FEAT_EVAL)
3279                      tvs != NULL ? (void *)tv_str(tvs, &arg_idx,
3280                                         NULL) :
3281     # endif
3282                         (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, &arg_cur),
/src/strings.c: 3033 in vim_vsnprintf_typval()
3027                 uj = 10 * uj + (unsigned int)(*p++ - '0');
3028                 arg_idx = uj;
3029     
3030                 ++p;
3031             }
3032     

                CID 1539914:    (FORWARD_NULL)
                Passing null pointer "ap_types" to "skip_to_arg", which dereferences it.

3033             j =
3034     # if defined(FEAT_EVAL)
3035                 tvs != NULL ? tv_nr(tvs, &arg_idx) :
3036     # endif
3037                 (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, &arg_cur),
3038                 va_arg(ap, int));
/src/strings.c: 3181 in vim_vsnprintf_typval()
3175                 str_arg = (char *)&uchar_arg;
3176                 break;
3177                 }
3178     
3179             case 's':
3180             case 'S':

                CID 1539914:    (FORWARD_NULL)
                Passing null pointer "ap_types" to "skip_to_arg", which dereferences it.

3181                 str_arg =
3182     # if defined(FEAT_EVAL)
3183                     tvs != NULL ? tv_str(tvs, &arg_idx, &tofree) :
3184     # endif
3185                         (skip_to_arg(ap_types, ap_start, &ap, &arg_idx, &arg_cur),
3186                         va_arg(ap, char *));


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/c1676845218@github.com>

cvwillegen

unread,
Aug 14, 2023, 9:41:26 AM8/14/23
to vim/vim, Subscribed

I will check for NULL in the function and make it an internal error, because this shouldn't happen.

The va_end() warning is not correct, because it is called at the end of the vim_vsprintf() function, and at the start of the skip_to_arg() function, so I made sure that all calls balance out. I'm not sure how to silence this warning?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/c1677339555@github.com>

Yegappan Lakshmanan

unread,
Aug 14, 2023, 10:20:03 AM8/14/23
to vim/vim, Subscribed

@yegappan commented on this pull request.


In src/strings.c:

> +	    semsg(_(e_positional_nr_out_of_bounds_str), arg_idx + 1, fmt);
+	    goto error;
+	}
+# endif
+    }
+
+    return OK;
+
+error:
+    vim_free(*ap_types);
+    *ap_types = NULL;
+    *num_posarg = 0;
+    return FAIL;
+}
+
+    void

This function is used only within this file, so this function can be changed to a static function.


In src/strings.c:

> +    return FAIL;
+}
+
+    void
+skip_to_arg(
+    const char	**ap_types,
+    va_list	ap_start,
+    va_list	*ap,
+    int		*arg_idx,
+    int		*arg_cur)
+{
+    int		arg_min = 0;
+
+    if (*arg_cur + 1 == *arg_idx)
+    {
+	++*arg_cur;

Can you add a comment here describing why this is needed (similar to the ones below)?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/review/1576949057@github.com>

zeertzjq

unread,
Aug 15, 2023, 6:10:38 AM8/15/23
to vim/vim, Subscribed

I will check for NULL in the function and make it an internal error, because this shouldn't happen.

I think it can happen, but in that case it is never dereferenced.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/c1678708109@github.com>

zeertzjq

unread,
Aug 15, 2023, 6:14:54 AM8/15/23
to vim/vim, Subscribed

For example, it can happen when the first format specifier is %c.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/c1678711834@github.com>

Christian Brabandt

unread,
Aug 20, 2023, 4:33:13 AM8/20/23
to vim/vim, Subscribed

@cvwillegen any updates here?


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/c1685224743@github.com>

cvwillegen

unread,
Aug 20, 2023, 4:36:11 AM8/20/23
to vim/vim, Subscribed

I'll get to it after my holiday...


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/c1685225304@github.com>

Christian Brabandt

unread,
Aug 20, 2023, 4:37:29 AM8/20/23
to vim/vim, Subscribed

sorry, no problem, please have your time. I just wanted not to get this lost.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/c1685225491@github.com>

Christian Brabandt

unread,
Aug 20, 2023, 4:54:38 AM8/20/23
to vim/vim, Subscribed

/remind me about it in 1 week


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/c1685228892@github.com>

cvwillegen

unread,
Sep 1, 2023, 6:00:41 AM9/1/23
to vim/vim, Subscribed

For example, it can happen at the first format specifier.

I looked at the code again. My conclusion is:

When there are no positional arguments specified, ap_types remains NULL. ap_types is, indeed, dereferenced in skip_to_arg() without checking for NULL, but only if the argument being requested differs from the last one + 1, and that can only happen if there are positional arguments. So, the skipping code is not executed.

If ap_types is NULL when positional arguments are specified, then the parse_fmt_types() function has failed allocating memory somewhere and it returns FAIL, and in this case the rest of the code is not executed.

I did add an internal error on the dereferencing (should not happen), but that's basically to shut up the warning :-) If it does happen, at least we know the format string an index where this went wrong.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/12140/c1702495502@github.com>

Reply all
Reply to author
Forward
0 new messages