diff options
Diffstat (limited to 'lua_cjson.c')
-rw-r--r-- | lua_cjson.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lua_cjson.c b/lua_cjson.c index 42672de..363466c 100644 --- a/lua_cjson.c +++ b/lua_cjson.c | |||
@@ -40,6 +40,7 @@ | |||
40 | #include <stdint.h> | 40 | #include <stdint.h> |
41 | #include <string.h> | 41 | #include <string.h> |
42 | #include <math.h> | 42 | #include <math.h> |
43 | #include <stdint.h> | ||
43 | #include <limits.h> | 44 | #include <limits.h> |
44 | #include <lua.h> | 45 | #include <lua.h> |
45 | #include <lauxlib.h> | 46 | #include <lauxlib.h> |
@@ -179,13 +180,13 @@ typedef struct { | |||
179 | 180 | ||
180 | typedef struct { | 181 | typedef struct { |
181 | json_token_type_t type; | 182 | json_token_type_t type; |
182 | int index; | 183 | size_t index; |
183 | union { | 184 | union { |
184 | const char *string; | 185 | const char *string; |
185 | double number; | 186 | double number; |
186 | int boolean; | 187 | int boolean; |
187 | } value; | 188 | } value; |
188 | int string_len; | 189 | size_t string_len; |
189 | } json_token_t; | 190 | } json_token_t; |
190 | 191 | ||
191 | static const char *char2escape[256] = { | 192 | static const char *char2escape[256] = { |
@@ -557,6 +558,8 @@ static void json_append_string(lua_State *l, strbuf_t *json, int lindex) | |||
557 | * This buffer is reused constantly for small strings | 558 | * This buffer is reused constantly for small strings |
558 | * If there are any excess pages, they won't be hit anyway. | 559 | * If there are any excess pages, they won't be hit anyway. |
559 | * This gains ~5% speedup. */ | 560 | * This gains ~5% speedup. */ |
561 | if (len > SIZE_MAX / 6 - 3) | ||
562 | abort(); /* Overflow check */ | ||
560 | strbuf_ensure_empty_length(json, len * 6 + 2); | 563 | strbuf_ensure_empty_length(json, len * 6 + 2); |
561 | 564 | ||
562 | strbuf_append_char_unsafe(json, '\"'); | 565 | strbuf_append_char_unsafe(json, '\"'); |
@@ -848,7 +851,7 @@ static int json_encode(lua_State *l) | |||
848 | strbuf_t local_encode_buf; | 851 | strbuf_t local_encode_buf; |
849 | strbuf_t *encode_buf; | 852 | strbuf_t *encode_buf; |
850 | char *json; | 853 | char *json; |
851 | int len; | 854 | size_t len; |
852 | 855 | ||
853 | luaL_argcheck(l, lua_gettop(l) == 1, 1, "expected 1 argument"); | 856 | luaL_argcheck(l, lua_gettop(l) == 1, 1, "expected 1 argument"); |
854 | 857 | ||