Skip to content
Snippets Groups Projects
Commit e2d9f664 authored by Serge Petrenko's avatar Serge Petrenko Committed by Vladimir Davydov
Browse files

lua/pickle: fix a typo

Prior to this patch format checking was broken for 'i' (integer) and 'N'
(big-endian integer). pickle.pack() rejected negative integers with
these formats. Fix this
parent fb3a2dfa
No related branches found
No related tags found
No related merge requests found
......@@ -109,14 +109,14 @@ lbox_pack(struct lua_State *L)
case 'I':
case 'i':
/* signed and unsigned 32-bit integers */
if (field.type != MP_UINT && field.ival != MP_INT)
if (field.type != MP_UINT && field.type != MP_INT)
luaL_error(L, "pickle.pack: expected 32-bit int");
luaL_region_dup(L, buf, &field.ival, sizeof(uint32_t));
break;
case 'N':
/* signed and unsigned 32-bit big endian integers */
if (field.type != MP_UINT && field.ival != MP_INT)
if (field.type != MP_UINT && field.type != MP_INT)
luaL_error(L, "pickle.pack: expected 32-bit int");
field.ival = htonl(field.ival);
......
......@@ -26,6 +26,14 @@ pickle.pack('s', 0x4d)
---
- "M\0"
...
pickle.pack('i', -1)
---
- !!binary /////w==
...
pickle.pack('N', -1)
---
- !!binary /////w==
...
pickle.pack('ssss', 25940, 29811, 28448, 11883)
---
- Test ok.
......
......@@ -7,6 +7,8 @@ pickle.pack('abc')
pickle.pack('a', ' - hello')
pickle.pack('Aa', ' - hello', ' world')
pickle.pack('s', 0x4d)
pickle.pack('i', -1)
pickle.pack('N', -1)
pickle.pack('ssss', 25940, 29811, 28448, 11883)
pickle.pack('SSSS', 25940, 29811, 28448, 11883)
pickle.pack('SSSSSSSS', 28493, 29550, 27680, 27497, 29541, 20512, 29285, 8556)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment