diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-05-22 18:59:07 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-05-22 18:59:07 -0300 |
commit | 29f0021837b9e4f5624806e03ef493ec488ea114 (patch) | |
tree | 3c9223037eb979a34d6c656e883f1586f3f32eec | |
parent | 7acddb871d6b008abdc4bc306ee683086282bac4 (diff) | |
download | lua-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.
-rw-r--r-- | iolib.c | 28 | ||||
-rw-r--r-- | strlib.c | 22 |
2 files changed, 26 insertions, 24 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** Input/output library to LUA | 3 | ** Input/output library to LUA |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_iolib="$Id: iolib.c,v 1.43 1996/04/30 21:13:55 roberto Exp roberto $"; | 6 | char *rcs_iolib="$Id: iolib.c,v 1.44 1996/05/03 20:10:59 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <ctype.h> | 9 | #include <ctype.h> |
@@ -141,7 +141,7 @@ static void io_appendto (void) | |||
141 | } | 141 | } |
142 | 142 | ||
143 | 143 | ||
144 | static char getformat (char *f, int *just, int *m, int *n) | 144 | static char getformat (char *f, int *just, long *m, int *n) |
145 | { | 145 | { |
146 | int t; | 146 | int t; |
147 | switch (*f++) | 147 | switch (*f++) |
@@ -211,7 +211,7 @@ static void read_until_blank (void) | |||
211 | if (c != EOF) ungetc(c,in); | 211 | if (c != EOF) ungetc(c,in); |
212 | } | 212 | } |
213 | 213 | ||
214 | static void read_m (int m) | 214 | static void read_m (size_t m) |
215 | { | 215 | { |
216 | int c; | 216 | int c; |
217 | while (m-- && (c = fgetc(in)) != EOF) | 217 | while (m-- && (c = fgetc(in)) != EOF) |
@@ -260,7 +260,8 @@ static void io_read (void) | |||
260 | read_free(); | 260 | read_free(); |
261 | else /* formatted */ | 261 | else /* formatted */ |
262 | { | 262 | { |
263 | int m, dummy1, dummy2; | 263 | long m; |
264 | int dummy1, dummy2; | ||
264 | switch (getformat(lua_check_string(1, "read"), &dummy1, &m, &dummy2)) | 265 | switch (getformat(lua_check_string(1, "read"), &dummy1, &m, &dummy2)) |
265 | { | 266 | { |
266 | case 's': | 267 | case 's': |
@@ -348,7 +349,7 @@ static void io_readuntil (void) | |||
348 | ** string -> nao se aplica | 349 | ** string -> nao se aplica |
349 | */ | 350 | */ |
350 | 351 | ||
351 | static int write_fill (int n, int c) | 352 | static int write_fill (size_t n, int c) |
352 | { | 353 | { |
353 | while (n--) | 354 | while (n--) |
354 | if (fputc(c, out) == EOF) | 355 | if (fputc(c, out) == EOF) |
@@ -356,11 +357,11 @@ static int write_fill (int n, int c) | |||
356 | return 1; | 357 | return 1; |
357 | } | 358 | } |
358 | 359 | ||
359 | static int write_string (char *s, int just, int m) | 360 | static int write_string (char *s, int just, long m) |
360 | { | 361 | { |
361 | int status; | 362 | int status; |
362 | int l = strlen(s); | 363 | size_t l = strlen(s); |
363 | int pre; /* number of blanks before string */ | 364 | size_t pre; /* number of blanks before string */ |
364 | if (m < 0) m = l; | 365 | if (m < 0) m = l; |
365 | else if (l > m) | 366 | else if (l > m) |
366 | { | 367 | { |
@@ -374,14 +375,14 @@ static int write_string (char *s, int just, int m) | |||
374 | return status; | 375 | return status; |
375 | } | 376 | } |
376 | 377 | ||
377 | static int write_quoted (int just, int m) | 378 | static int write_quoted (int just, long m) |
378 | { | 379 | { |
379 | luaI_addchar(0); | 380 | luaI_addchar(0); |
380 | luaI_addquoted(lua_check_string(1, "write")); | 381 | luaI_addquoted(lua_check_string(1, "write")); |
381 | return write_string(luaI_addchar(0), just, m); | 382 | return write_string(luaI_addchar(0), just, m); |
382 | } | 383 | } |
383 | 384 | ||
384 | static int write_float (int just, int m, int n) | 385 | static int write_float (int just, long m, int n) |
385 | { | 386 | { |
386 | char buffer[100]; | 387 | char buffer[100]; |
387 | lua_Object p = lua_getparam(1); | 388 | lua_Object p = lua_getparam(1); |
@@ -396,7 +397,7 @@ static int write_float (int just, int m, int n) | |||
396 | } | 397 | } |
397 | 398 | ||
398 | 399 | ||
399 | static int write_int (int just, int m, int n) | 400 | static int write_int (int just, long m, int n) |
400 | { | 401 | { |
401 | char buffer[100]; | 402 | char buffer[100]; |
402 | lua_Object p = lua_getparam(1); | 403 | lua_Object p = lua_getparam(1); |
@@ -425,7 +426,8 @@ static void io_write (void) | |||
425 | } | 426 | } |
426 | else /* formated */ | 427 | else /* formated */ |
427 | { | 428 | { |
428 | int just, m, n; | 429 | long m; |
430 | int just, n; | ||
429 | switch (getformat(lua_check_string(2, "write"), &just, &m, &n)) | 431 | switch (getformat(lua_check_string(2, "write"), &just, &m, &n)) |
430 | { | 432 | { |
431 | case 's': | 433 | case 's': |
@@ -490,7 +492,7 @@ static void io_errorno (void) | |||
490 | 492 | ||
491 | 493 | ||
492 | /* | 494 | /* |
493 | ** To get a environment variable | 495 | ** To get an environment variable |
494 | */ | 496 | */ |
495 | static void io_getenv (void) | 497 | static void io_getenv (void) |
496 | { | 498 | { |
@@ -3,7 +3,7 @@ | |||
3 | ** String library to LUA | 3 | ** String library to LUA |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_strlib="$Id: strlib.c,v 1.22 1996/03/22 17:57:24 roberto Exp roberto $"; | 6 | char *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 | ||
41 | static int lua_opt_number (int numArg, int def, char *funcname) | 41 | static 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 | ||
47 | char *luaI_addchar (int c) | 47 | char *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) | |||
114 | static void str_sub (void) | 114 | static 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) | |||
162 | static void str_ascii (void) | 162 | static 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]); |