Parcourir la source

variables which contain string lengths must be long (if they also may
be negative) or size_t.

Roberto Ierusalimschy il y a 29 ans
Parent
commit
29f0021837
2 fichiers modifiés avec 26 ajouts et 24 suppressions
  1. 15 13
      iolib.c
  2. 11 11
      strlib.c

+ 15 - 13
iolib.c

@@ -3,7 +3,7 @@
 ** Input/output library to LUA
 ** Input/output library to LUA
 */
 */
 
 
-char *rcs_iolib="$Id: iolib.c,v 1.43 1996/04/30 21:13:55 roberto Exp roberto $";
+char *rcs_iolib="$Id: iolib.c,v 1.44 1996/05/03 20:10:59 roberto Exp roberto $";
 
 
 #include <stdio.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <ctype.h>
@@ -141,7 +141,7 @@ static void io_appendto (void)
 }
 }
 
 
 
 
-static char getformat (char *f, int *just, int *m, int *n)
+static char getformat (char *f, int *just, long *m, int *n)
 {
 {
   int t;
   int t;
   switch (*f++)
   switch (*f++)
@@ -211,7 +211,7 @@ static void read_until_blank (void)
   if (c != EOF) ungetc(c,in);
   if (c != EOF) ungetc(c,in);
 }
 }
 
 
-static void read_m (int m)
+static void read_m (size_t m)
 {
 {
   int c;
   int c;
   while (m-- && (c = fgetc(in)) != EOF)
   while (m-- && (c = fgetc(in)) != EOF)
@@ -260,7 +260,8 @@ static void io_read (void)
     read_free();
     read_free();
   else				/* formatted */
   else				/* formatted */
   {
   {
-    int m, dummy1, dummy2;
+    long m;
+    int dummy1, dummy2;
     switch (getformat(lua_check_string(1, "read"), &dummy1, &m, &dummy2))
     switch (getformat(lua_check_string(1, "read"), &dummy1, &m, &dummy2))
     {
     {
       case 's':
       case 's':
@@ -348,7 +349,7 @@ static void io_readuntil (void)
 **			string -> nao se aplica
 **			string -> nao se aplica
 */
 */
 
 
-static int write_fill (int n, int c)
+static int write_fill (size_t n, int c)
 {
 {
   while (n--)
   while (n--)
     if (fputc(c, out) == EOF)
     if (fputc(c, out) == EOF)
@@ -356,11 +357,11 @@ static int write_fill (int n, int c)
   return 1;
   return 1;
 }
 }
 
 
-static int write_string (char *s, int just, int m)
+static int write_string (char *s, int just, long m)
 {
 {
   int status;
   int status;
-  int l = strlen(s);
-  int pre;  /* number of blanks before string */
+  size_t l = strlen(s);
+  size_t pre;  /* number of blanks before string */
   if (m < 0) m = l;
   if (m < 0) m = l;
   else if (l > m)
   else if (l > m)
   {
   {
@@ -374,14 +375,14 @@ static int write_string (char *s, int just, int m)
   return status;
   return status;
 }
 }
 
 
-static int write_quoted (int just, int m)
+static int write_quoted (int just, long m)
 {
 {
   luaI_addchar(0);
   luaI_addchar(0);
   luaI_addquoted(lua_check_string(1, "write"));
   luaI_addquoted(lua_check_string(1, "write"));
   return write_string(luaI_addchar(0), just, m);
   return write_string(luaI_addchar(0), just, m);
 }
 }
 
 
-static int write_float (int just, int m, int n)
+static int write_float (int just, long m, int n)
 {
 {
   char buffer[100];
   char buffer[100];
   lua_Object p = lua_getparam(1);
   lua_Object p = lua_getparam(1);
@@ -396,7 +397,7 @@ static int write_float (int just, int m, int n)
 }
 }
 
 
 
 
-static int write_int (int just, int m, int n)
+static int write_int (int just, long m, int n)
 {
 {
   char buffer[100];
   char buffer[100];
   lua_Object p = lua_getparam(1);
   lua_Object p = lua_getparam(1);
@@ -425,7 +426,8 @@ static void io_write (void)
   }
   }
   else					/* formated */
   else					/* formated */
   {
   {
-    int just, m, n;
+    long m;
+    int just, n;
     switch (getformat(lua_check_string(2, "write"), &just, &m, &n))
     switch (getformat(lua_check_string(2, "write"), &just, &m, &n))
     {
     {
       case 's':
       case 's':
@@ -490,7 +492,7 @@ static void io_errorno (void)
 
 
 
 
 /*
 /*
-** To get a environment variable
+** To get an environment variable
 */
 */
 static void io_getenv (void)
 static void io_getenv (void)
 {
 {

+ 11 - 11
strlib.c

@@ -3,7 +3,7 @@
 ** String library to LUA
 ** String library to LUA
 */
 */
 
 
-char *rcs_strlib="$Id: strlib.c,v 1.22 1996/03/22 17:57:24 roberto Exp roberto $";
+char *rcs_strlib="$Id: strlib.c,v 1.23 1996/04/30 21:13:55 roberto Exp roberto $";
 
 
 #include <string.h>
 #include <string.h>
 #include <stdio.h>
 #include <stdio.h>
@@ -38,17 +38,17 @@ double lua_check_number (int numArg, char *funcname)
   return lua_getnumber(o);
   return lua_getnumber(o);
 }
 }
 
 
-static int lua_opt_number (int numArg, int def, char *funcname)
+static long lua_opt_number (int numArg, long def, char *funcname)
 {
 {
   return (lua_getparam(numArg) == LUA_NOOBJECT) ? def :
   return (lua_getparam(numArg) == LUA_NOOBJECT) ? def :
-                              (int)lua_check_number(numArg, funcname);
+                              (long)lua_check_number(numArg, funcname);
 }
 }
 
 
 char *luaI_addchar (int c)
 char *luaI_addchar (int c)
 {
 {
   static char *buff = NULL;
   static char *buff = NULL;
-  static int max = 0;
-  static int n = 0;
+  static size_t max = 0;
+  static size_t n = 0;
   if (n >= max)
   if (n >= max)
   {
   {
     if (max == 0)
     if (max == 0)
@@ -80,12 +80,12 @@ static void str_find (void)
 {
 {
  char *s1 = lua_check_string(1, "strfind");
  char *s1 = lua_check_string(1, "strfind");
  char *s2 = lua_check_string(2, "strfind");
  char *s2 = lua_check_string(2, "strfind");
- int init = lua_opt_number(3, 1, "strfind") - 1;
+ long init = lua_opt_number(3, 1, "strfind") - 1;
  char *f = (init>=0 && init<=strlen(s1)) ? strstr(s1+init,s2) : NULL;
  char *f = (init>=0 && init<=strlen(s1)) ? strstr(s1+init,s2) : NULL;
  if (f != NULL)
  if (f != NULL)
  {
  {
-  int pos = f-s1+1;
-  if (lua_opt_number(4, INT_MAX, "strfind") >= pos+strlen(s2)-1)
+  size_t pos = f-s1+1;
+  if (lua_opt_number(4, LONG_MAX, "strfind") >= pos+strlen(s2)-1)
    lua_pushnumber (pos);
    lua_pushnumber (pos);
   else
   else
    lua_pushnil();
    lua_pushnil();
@@ -114,8 +114,8 @@ static void str_len (void)
 static void str_sub (void)
 static void str_sub (void)
 {
 {
  char *s = lua_check_string(1, "strsub");
  char *s = lua_check_string(1, "strsub");
- int start = (int)lua_check_number(2, "strsub");
- int end = lua_opt_number(3, strlen(s), "strsub");
+ long start = (long)lua_check_number(2, "strsub");
+ long end = lua_opt_number(3, strlen(s), "strsub");
  if (end < start || start < 1 || end > strlen(s))
  if (end < start || start < 1 || end > strlen(s))
   lua_pushliteral("");
   lua_pushliteral("");
  else
  else
@@ -162,7 +162,7 @@ static void str_upper (void)
 static void str_ascii (void)
 static void str_ascii (void)
 {
 {
   char *s = lua_check_string(1, "ascii");
   char *s = lua_check_string(1, "ascii");
-  int pos = lua_opt_number(2, 1, "ascii") - 1;
+  long pos = lua_opt_number(2, 1, "ascii") - 1;
   if (pos<0 || pos>=strlen(s))
   if (pos<0 || pos>=strlen(s))
     lua_arg_error("ascii");
     lua_arg_error("ascii");
   lua_pushnumber(s[pos]);
   lua_pushnumber(s[pos]);