diff options
-rw-r--r-- | lstrlib.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -1,11 +1,12 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.180 2013/06/07 14:51:10 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.181 2013/06/19 14:29:01 roberto Exp roberto $ |
3 | ** Standard library for string operations and pattern-matching | 3 | ** Standard library for string operations and pattern-matching |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
6 | 6 | ||
7 | 7 | ||
8 | #include <ctype.h> | 8 | #include <ctype.h> |
9 | #include <limits.h> | ||
9 | #include <stddef.h> | 10 | #include <stddef.h> |
10 | #include <stdio.h> | 11 | #include <stdio.h> |
11 | #include <stdlib.h> | 12 | #include <stdlib.h> |
@@ -102,8 +103,12 @@ static int str_upper (lua_State *L) { | |||
102 | } | 103 | } |
103 | 104 | ||
104 | 105 | ||
105 | /* reasonable limit to avoid arithmetic overflow */ | 106 | /* reasonable limit to avoid arithmetic overflow and strings too big */ |
106 | #define MAXSIZE ((~(size_t)0) >> 1) | 107 | #if INT_MAX / 2 <= 0x10000000 |
108 | #define MAXSIZE ((size_t)(INT_MAX / 2)) | ||
109 | #else | ||
110 | #define MAXSIZE ((size_t)0x10000000) | ||
111 | #endif | ||
107 | 112 | ||
108 | static int str_rep (lua_State *L) { | 113 | static int str_rep (lua_State *L) { |
109 | size_t l, lsep; | 114 | size_t l, lsep; |