fix(lua): fix architecture-dependent behavior in usercmd "reg" (#20384)

I don't think using an integer as a NUL-terminated string can work on
big-endian systems, at least.

This is also not tested. Add a test.

Also fix a mistake in the docs of nvim_parse_cmd.
This commit is contained in:
zeertzjq
2022-09-28 18:27:59 +08:00
committed by GitHub
parent eb4844b5ed
commit 35e2c4a2ed
4 changed files with 42 additions and 6 deletions

View File

@@ -37,7 +37,7 @@
/// specified and two elements if both range items were specified.
/// - count: (number) Any |<count>| that was supplied to the command. -1 if command cannot
/// take a count.
/// - reg: (number) The optional command |<register>|, if specified. Empty string if not
/// - reg: (string) The optional command |<register>|, if specified. Empty string if not
/// specified or if command cannot take a register.
/// - bang: (boolean) Whether command contains a |<bang>| (!) modifier.
/// - args: (array) Command arguments.
@@ -165,9 +165,7 @@ Dictionary nvim_parse_cmd(String str, Dictionary opts, Error *err)
PUT(result, "count", INTEGER_OBJ(-1));
}
char reg[2];
reg[0] = (char)ea.regname;
reg[1] = '\0';
char reg[2] = { (char)ea.regname, NUL };
PUT(result, "reg", CSTR_TO_OBJ(reg));
PUT(result, "bang", BOOLEAN_OBJ(ea.forceit));