aboutsummaryrefslogtreecommitdiff
path: root/strlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-05-22 18:59:07 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-05-22 18:59:07 -0300
commit29f0021837b9e4f5624806e03ef493ec488ea114 (patch)
tree3c9223037eb979a34d6c656e883f1586f3f32eec /strlib.c
parent7acddb871d6b008abdc4bc306ee683086282bac4 (diff)
downloadlua-29f0021837b9e4f5624806e03ef493ec488ea114.tar.gz
lua-29f0021837b9e4f5624806e03ef493ec488ea114.tar.bz2
lua-29f0021837b9e4f5624806e03ef493ec488ea114.zip
variables which contain string lengths must be long (if they also may
be negative) or size_t.
Diffstat (limited to 'strlib.c')
-rw-r--r--strlib.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/strlib.c b/strlib.c
index a3467050..061581e3 100644
--- a/strlib.c
+++ b/strlib.c
@@ -3,7 +3,7 @@
3** String library to LUA 3** String library to LUA
4*/ 4*/
5 5
6char *rcs_strlib="$Id: strlib.c,v 1.22 1996/03/22 17:57:24 roberto Exp roberto $"; 6char *rcs_strlib="$Id: strlib.c,v 1.23 1996/04/30 21:13:55 roberto Exp roberto $";
7 7
8#include <string.h> 8#include <string.h>
9#include <stdio.h> 9#include <stdio.h>
@@ -38,17 +38,17 @@ double lua_check_number (int numArg, char *funcname)
38 return lua_getnumber(o); 38 return lua_getnumber(o);
39} 39}
40 40
41static int lua_opt_number (int numArg, int def, char *funcname) 41static long lua_opt_number (int numArg, long def, char *funcname)
42{ 42{
43 return (lua_getparam(numArg) == LUA_NOOBJECT) ? def : 43 return (lua_getparam(numArg) == LUA_NOOBJECT) ? def :
44 (int)lua_check_number(numArg, funcname); 44 (long)lua_check_number(numArg, funcname);
45} 45}
46 46
47char *luaI_addchar (int c) 47char *luaI_addchar (int c)
48{ 48{
49 static char *buff = NULL; 49 static char *buff = NULL;
50 static int max = 0; 50 static size_t max = 0;
51 static int n = 0; 51 static size_t n = 0;
52 if (n >= max) 52 if (n >= max)
53 { 53 {
54 if (max == 0) 54 if (max == 0)
@@ -80,12 +80,12 @@ static void str_find (void)
80{ 80{
81 char *s1 = lua_check_string(1, "strfind"); 81 char *s1 = lua_check_string(1, "strfind");
82 char *s2 = lua_check_string(2, "strfind"); 82 char *s2 = lua_check_string(2, "strfind");
83 int init = lua_opt_number(3, 1, "strfind") - 1; 83 long init = lua_opt_number(3, 1, "strfind") - 1;
84 char *f = (init>=0 && init<=strlen(s1)) ? strstr(s1+init,s2) : NULL; 84 char *f = (init>=0 && init<=strlen(s1)) ? strstr(s1+init,s2) : NULL;
85 if (f != NULL) 85 if (f != NULL)
86 { 86 {
87 int pos = f-s1+1; 87 size_t pos = f-s1+1;
88 if (lua_opt_number(4, INT_MAX, "strfind") >= pos+strlen(s2)-1) 88 if (lua_opt_number(4, LONG_MAX, "strfind") >= pos+strlen(s2)-1)
89 lua_pushnumber (pos); 89 lua_pushnumber (pos);
90 else 90 else
91 lua_pushnil(); 91 lua_pushnil();
@@ -114,8 +114,8 @@ static void str_len (void)
114static void str_sub (void) 114static void str_sub (void)
115{ 115{
116 char *s = lua_check_string(1, "strsub"); 116 char *s = lua_check_string(1, "strsub");
117 int start = (int)lua_check_number(2, "strsub"); 117 long start = (long)lua_check_number(2, "strsub");
118 int end = lua_opt_number(3, strlen(s), "strsub"); 118 long end = lua_opt_number(3, strlen(s), "strsub");
119 if (end < start || start < 1 || end > strlen(s)) 119 if (end < start || start < 1 || end > strlen(s))
120 lua_pushliteral(""); 120 lua_pushliteral("");
121 else 121 else
@@ -162,7 +162,7 @@ static void str_upper (void)
162static void str_ascii (void) 162static void str_ascii (void)
163{ 163{
164 char *s = lua_check_string(1, "ascii"); 164 char *s = lua_check_string(1, "ascii");
165 int pos = lua_opt_number(2, 1, "ascii") - 1; 165 long pos = lua_opt_number(2, 1, "ascii") - 1;
166 if (pos<0 || pos>=strlen(s)) 166 if (pos<0 || pos>=strlen(s))
167 lua_arg_error("ascii"); 167 lua_arg_error("ascii");
168 lua_pushnumber(s[pos]); 168 lua_pushnumber(s[pos]);