eval: Fix overflow in error message in f_json_decode

This commit is contained in:
ZyX
2016-03-20 19:55:59 +03:00
parent 9709cf2cdb
commit af7ff808c7
2 changed files with 9 additions and 1 deletions

View File

@@ -11618,7 +11618,7 @@ static void f_json_decode(typval_T *argvars, typval_T *rettv)
return; return;
} }
if (json_decode_string(s, len, rettv) == FAIL) { if (json_decode_string(s, len, rettv) == FAIL) {
EMSG2(_("E474: Failed to parse %s"), s); emsgf(_("E474: Failed to parse %.*s"), (int) len, s);
rettv->v_type = VAR_NUMBER; rettv->v_type = VAR_NUMBER;
rettv->vval.v_number = 0; rettv->vval.v_number = 0;
} }

View File

@@ -6,6 +6,7 @@ local eq = helpers.eq
local eval = helpers.eval local eval = helpers.eval
local execute = helpers.execute local execute = helpers.execute
local exc_exec = helpers.exc_exec local exc_exec = helpers.exc_exec
local redir_exec = helpers.redir_exec
describe('json_decode() function', function() describe('json_decode() function', function()
local restart = function(cmd) local restart = function(cmd)
@@ -529,6 +530,13 @@ describe('json_decode() function', function()
restart('set encoding=latin1') restart('set encoding=latin1')
eq(('%c'):format(0xAB), funcs.json_decode('"«"')) eq(('%c'):format(0xAB), funcs.json_decode('"«"'))
end) end)
it('does not overflow when writing error message about decoding ["", ""]',
function()
eq('\nE474: Attempt to decode a blank string'
.. '\nE474: Failed to parse \n',
redir_exec('call json_decode(["", ""])'))
end)
end) end)
describe('json_encode() function', function() describe('json_encode() function', function()