summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorYang Tse <yangsita@gmail.com>2010-11-28 23:11:14 +0100
committerYang Tse <yangsita@gmail.com>2010-11-28 23:11:14 +0100
commit5db0a412ff6972e51ccddaf1e8d6a27c8de4990f (patch)
tree8c8cfa609c25c68929554ac1e24eaa4084683152 /src
parentcbe67a1b71f7098779b8c0cecccb60382cec2d20 (diff)
downloadcurl-5db0a412ff6972e51ccddaf1e8d6a27c8de4990f.tar.gz
atoi: remove atoi usage
Diffstat (limited to 'src')
-rw-r--r--src/main.c27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/main.c b/src/main.c
index 2f81ef4e8..7a6c1c8b3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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