From 6259b74349f910c1df0a178c4b362ffcd24ff0e9 Mon Sep 17 00:00:00 2001
From: Konstantin Osipov <kostja@tarantool.org>
Date: Thu, 6 Dec 2012 18:22:54 +0400
Subject: [PATCH] box-unpack: minor edits

---
 include/pickle.h    |  8 ++++----
 src/lua/init.m      | 20 ++++++++++----------
 src/pickle.m        |  2 --
 test/box/lua.result |  2 +-
 4 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/include/pickle.h b/include/pickle.h
index d42b130f11..92287cb3ac 100644
--- a/include/pickle.h
+++ b/include/pickle.h
@@ -77,7 +77,7 @@ load_varint32_s(void **data, size_t size)
 	}
 
 	if (unlikely(size < 3))
-		tnt_raise(IllegalParams, :"varint is too short (expected 3+ bytes)");
+		tnt_raise(IllegalParams, :"BER int is too short (expected 3+ bytes)");
 
 	if (!(b[2] & 0x80)) {
 		*data += 3;
@@ -85,7 +85,7 @@ load_varint32_s(void **data, size_t size)
 	}
 
 	if (unlikely(size < 4))
-		tnt_raise(IllegalParams, :"varint is too short (expected 4+ bytes)");
+		tnt_raise(IllegalParams, :"BER int is too short (expected 4+ bytes)");
 
 	if (!(b[3] & 0x80)) {
 		*data += 4;
@@ -94,7 +94,7 @@ load_varint32_s(void **data, size_t size)
 	}
 
 	if (unlikely(size < 5))
-		tnt_raise(IllegalParams, :"varint is too short (expected 5+ bytes)");
+		tnt_raise(IllegalParams, :"BER int is too short (expected 5+ bytes)");
 
 	if (!(b[4] & 0x80)) {
 		*data += 5;
@@ -102,7 +102,7 @@ load_varint32_s(void **data, size_t size)
 			(b[2] & 0x7f) << 14 | (b[3] & 0x7f) << 7 | (b[4] & 0x7f);
 	}
 
-	tnt_raise(IllegalParams, :"incorrect varint format");
+	tnt_raise(IllegalParams, :"incorrect BER integer format");
 }
 
 static inline u32
diff --git a/src/lua/init.m b/src/lua/init.m
index 7606793855..c40226c680 100644
--- a/src/lua/init.m
+++ b/src/lua/init.m
@@ -373,10 +373,10 @@ lbox_unpack(struct lua_State *L)
 	u16 u16buf;
 	u32 u32buf;
 
-#define CHECK_SIZE(cur) { if (unlikely((cur) >= end))                          \
-		luaL_error(L, "box.unpack('%c'): got %d bytes (expected: %d+)",\
-			   *f, (int) (end - str), (int) 1 + ((cur) - str));}
-
+#define CHECK_SIZE(cur) if (unlikely((cur) >= end)) {	                \
+	luaL_error(L, "box.unpack('%c'): got %d bytes (expected: %d+)",	\
+		   *f, (int) (end - str), (int) 1 + ((cur) - str));	\
+}
 	while (*f) {
 		switch (*f) {
 		case 'b':
@@ -404,16 +404,16 @@ lbox_unpack(struct lua_State *L)
 			s += 8;
 			break;
 		case 'w':
-			/* exception is thrown on error */
+			/* load_varint32_s throws exception on error. */
 			u32buf = load_varint32_s((void *)&s, end - s);
 			lua_pushnumber(L, u32buf);
 			break;
 		case 'P':
 		case 'p':
-			/* exception is thrown on error */
+			/* load_varint32_s throws exception on error. */
 			u32buf = load_varint32_s((void *)&s, end - s);
-			CHECK_SIZE(s + u32buf-1);
-			lua_pushlstring (L, (const char *) s, u32buf);
+			CHECK_SIZE(s + u32buf - 1);
+			lua_pushlstring(L, (const char *) s, u32buf);
 			s += u32buf;
 			break;
 		case '=':
@@ -454,7 +454,7 @@ lbox_unpack(struct lua_State *L)
 			s += 5;
 			break;
 		default:
-			luaL_error(L, "box.unpack: unsupported pack "
+			luaL_error(L, "box.unpack: unsupported "
 				   "format specifier '%c'", *f);
 		}
 		i++;
@@ -465,7 +465,7 @@ lbox_unpack(struct lua_State *L)
 
 	if (s != end) {
 		luaL_error(L, "box.unpack('%s'): too many bytes: "
-			   "unpacked %d, size %d",
+			   "unpacked %d, total %d",
 			   format, s - str, str_size);
 	}
 
diff --git a/src/pickle.m b/src/pickle.m
index fcc00d3600..a4cc72d224 100644
--- a/src/pickle.m
+++ b/src/pickle.m
@@ -31,13 +31,11 @@
 #include <fiber.h>
 #include <iproto.h>		/* for err codes */
 #include "say.h"
-#include "exception.h"
 
 /* caller must ensure that there is space in target */
 u8 *
 save_varint32(u8 *target, u32 value)
 {
-
 	if (value >= (1 << 7)) {
 		if (value >= (1 << 14)) {
 			if (value >= (1 << 21)) {
diff --git a/test/box/lua.result b/test/box/lua.result
index 439b4f01b9..fa2d29fe1a 100644
--- a/test/box/lua.result
+++ b/test/box/lua.result
@@ -159,7 +159,7 @@ error: 'box.unpack(''i''): got 4 bytes (expected: 8+)'
 ...
 lua box.unpack('i', box.pack('ii', 1, 1))
 ---
-error: 'box.unpack(''i''): too many bytes: unpacked 4, size 8'
+error: 'box.unpack(''i''): too many bytes: unpacked 4, total 8'
 ...
 lua box.unpack('+p', box.pack('=p', 1, '666'))
 ---
-- 
GitLab