]> granicus.if.org Git - curl/commitdiff
atoi: remove atoi usage
authorYang Tse <yangsita@gmail.com>
Sun, 28 Nov 2010 22:11:14 +0000 (23:11 +0100)
committerYang Tse <yangsita@gmail.com>
Sun, 28 Nov 2010 22:11:14 +0000 (23:11 +0100)
12 files changed:
docs/examples/chkspeed.c
lib/cookie.c
lib/ftp.c
lib/ldap.c
lib/smtp.c
lib/url.c
src/main.c
tests/libtest/first.c
tests/libtest/lib521.c
tests/libtest/lib562.c
tests/server/rtspd.c
tests/server/sws.c

index d802469b81c0f74d36e4dfff35b525a073e9755d..00db5bf1d4bfd61eeea7b01ba35dc8b18787c623 100644 (file)
@@ -71,7 +71,7 @@ int main(int argc, char *argv[])
         } else if (strncasecmp(*argv, "-T", 2) == 0) {
           prttime = 1;
         } else if (strncasecmp(*argv, "-M=", 3) == 0) {
-          int m = atoi(*argv + 3);
+          long m = strtol(argv+3, NULL, 10);
           switch(m) {
             case   1: url = URL_1M;
                       break;
index 21617adce5ca93c62fa05587b07a6e5e650d587c..c6460a1003d5db8104c25a7a7dc0831b020e0f62 100644 (file)
@@ -353,8 +353,8 @@ Curl_cookie_add(struct SessionHandle *data,
               break;
             }
             co->expires =
-              atoi((*co->maxage=='\"')?&co->maxage[1]:&co->maxage[0]) +
-              (long)now;
+              strtol((*co->maxage=='\"')?&co->maxage[1]:&co->maxage[0],NULL,10)
+                + (long)now;
           }
           else if(Curl_raw_equal("expires", name)) {
             strstore(&co->expirestr, whatptr);
index 5c0be38f5b1fe5e3176b12959ad0096e4e021155..0558e0563a5b8bd60e11a9659bde62ac516c8c95 100644 (file)
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -379,7 +379,7 @@ static int ftp_endofresp(struct pingpong *pp,
   size_t len = pp->nread_resp;
 
   if((len > 3) && LASTLINE(line)) {
-    *code = atoi(line);
+    *code = strtol(line, NULL, 10);
     return 1;
   }
   return 0;
index d6556c9054cee1a24c631f6e20e839709cee4164..529e45212732f7940c7af60dba60ae9555f7d110 100644 (file)
@@ -473,7 +473,7 @@ static void _ldap_trace (const char *fmt, ...)
 
   if(do_trace == -1) {
     const char *env = getenv("CURL_TRACE");
-    do_trace = (env && atoi(env) > 0);
+    do_trace = (env && strtol(env, NULL, 10) > 0);
   }
   if(!do_trace)
     return;
index 55e03d5a7ba159a11b4ff4350b077369e286c782..5ccdcb671b1ec342707466d8fdad04ecbffe5764 100644 (file)
@@ -226,7 +226,7 @@ static int smtp_endofresp(struct pingpong *pp, int *resp)
     return FALSE;       /* Nothing for us. */
 
   if((result = line[3] == ' '))
-    *resp = atoi(line);
+    *resp = strtol(line, NULL, 10);
 
   line += 4;
   len -= 4;
index e915c794772c504042c890f9e054a58153fc306e..0aed7b44b6a52592f6787afcf39848d5028ae443 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -4155,7 +4155,7 @@ static CURLcode parse_proxy(struct SessionHandle *data,
     *prox_portno = 0x0; /* cut off number from host name */
     prox_portno ++;
     /* now set the local port number */
-    conn->port = atoi(prox_portno);
+    conn->port = strtol(prox_portno, NULL, 10);
   }
   else {
     /* without a port number after the host name, some people seem to use
index 2f81ef4e8d1241b32bde1fbd15fad14a4ebc43e3..7a6c1c8b332f15d8a5f6a198d2fddf3824c3c926 100644 (file)
@@ -1509,12 +1509,15 @@ static void cleanarg(char *str)
 
 static int str2num(long *val, const char *str)
 {
-  int retcode = 0;
-  if(str && ISDIGIT(*str))
-    *val = atoi(str);
-  else
-    retcode = 1; /* badness */
-  return retcode;
+  if(str && ISDIGIT(*str)) {
+    char *endptr;
+    long num = strtol(str, &endptr, 10);
+    if((endptr != str) && (endptr == str + strlen(str))) {
+      *val = num;
+      return 0;  /* Ok */
+    }
+  }
+  return 1; /* badness */
 }
 
 /*
@@ -3711,7 +3714,12 @@ void progressbarinit(struct ProgressData *bar,
    * we're using our own way to determine screen width */
   colp = curlx_getenv("COLUMNS");
   if(colp != NULL) {
-    bar->width = atoi(colp);
+    char *endptr;
+    long num = strtol(colp, &endptr, 10);
+    if((endptr != colp) && (endptr == colp + strlen(colp)) && (num > 0))
+      bar->width = (int)num;
+    else
+      bar->width = 79;
     curl_free(colp);
   }
   else
@@ -4513,7 +4521,10 @@ operate(struct Configurable *config, int argc, argv_item_t argv[])
   }
   env = curlx_getenv("CURL_MEMLIMIT");
   if(env) {
-    curl_memlimit(atoi(env));
+    char *endptr;
+    long num = strtol(env, &endptr, 10);
+    if((endptr != env) && (endptr == env + strlen(env)) && (num > 0))
+      curl_memlimit(num);
     curl_free(env);
   }
 #endif
index 770f9d527deaa84faf436c304ef8532e72fb8b7d..a0e713f48938d048beb532e14d9c67b6def1783d 100644 (file)
@@ -59,7 +59,10 @@ int main(int argc, char **argv)
   /* this enables the fail-on-alloc-number-N functionality */
   env = curl_getenv("CURL_MEMLIMIT");
   if(env) {
-    curl_memlimit(atoi(env));
+    char *endptr;
+    long num = strtol(env, &endptr, 10);
+    if((endptr != env) && (endptr == env + strlen(env)) && (num > 0))
+      curl_memlimit(num);
     curl_free(env);
   }
 #endif
index a4ae5558afe8638d8cf0d692cb22631707e7d983..9e79cb41e2ade21baa66c43a3761c2f74d51373d 100644 (file)
@@ -28,7 +28,7 @@ int test(char *URL)
   }
 
   test_setopt(curl, CURLOPT_URL, URL);
-  test_setopt(curl, CURLOPT_PORT, atoi(libtest_arg2));
+  test_setopt(curl, CURLOPT_PORT, strtol(libtest_arg2, NULL, 10));
   test_setopt(curl, CURLOPT_USERPWD, "xxx:yyy");
   test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
index d78ecce25f27439644954090d259af0f9ebb75fd..acdd79aabb8f7757dff31edb38917c8859556573 100644 (file)
@@ -57,7 +57,7 @@ int test(char *URL)
   test_setopt(curl, CURLOPT_VERBOSE, 1L);
 
   /* set port number */
-  test_setopt(curl, CURLOPT_PORT, atoi(libtest_arg2) );
+  test_setopt(curl, CURLOPT_PORT, strtol(libtest_arg2, NULL, 10));
 
   /* specify target */
   test_setopt(curl,CURLOPT_URL, URL);
index d2471b99845837dcf84876fc89c6d6445ce5fd09..f751f11535adb7314f30895f53ca3f9db695c60a 100644 (file)
@@ -531,8 +531,8 @@ static int ProcessRequest(struct httprequest *req)
           /* if the host name starts with test, the port number used in the
              CONNECT line will be used as test number! */
           char *portp = strchr(doc, ':');
-          if(portp)
-            req->testno = atoi(portp+1);
+          if(portp && (*(portp+1) != '\0') && ISDIGIT(*(portp+1)))
+            req->testno = strtol(portp+1, NULL, 10);
           else
             req->testno = DOCNUMBER_CONNECT;
         }
index 1650226e616a011043ea9cc436464d2d9764e34f..65a61c2ce818b5bc4c131ffebfea7bcf52dcd7d0 100644 (file)
@@ -467,8 +467,8 @@ static int ProcessRequest(struct httprequest *req)
           /* if the host name starts with test, the port number used in the
              CONNECT line will be used as test number! */
           char *portp = strchr(doc, ':');
-          if(portp)
-            req->testno = atoi(portp+1);
+          if(portp && (*(portp+1) != '\0') && ISDIGIT(*(portp+1)))
+            req->testno = strtol(portp+1, NULL, 10);
           else
             req->testno = DOCNUMBER_CONNECT;
         }