Commit 64852bbd authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Use strtol instead of atol in more places, and avoid a compiler

warning.  (Bug 143).
* src/server/conf-file.c (convert_to_ulong): New function.
(assign_text_no): Use it instead of convert_to_long to get rid of
a compiler warning.
(assign_ulong): Use convert_to_ulong instead of atol.
(assign_uint): Ditto.  Check for overflow.
parent 26856e25
2006-07-26 Per Cederqvist <ceder@lysator.liu.se>
 
Use strtol instead of atol in more places, and avoid a compiler
warning. (Bug 143).
* src/server/conf-file.c (convert_to_ulong): New function.
(assign_text_no): Use it instead of convert_to_long to get rid of
a compiler warning.
(assign_ulong): Use convert_to_ulong instead of atol.
(assign_uint): Ditto. Check for overflow.
Use strtol instead of atol. (Bug 143).
* src/server/conf-file.c (convert_to_long): New function.
(assign_text_no): Use it instead of using atol. Check for
......
......@@ -274,15 +274,32 @@ convert_to_long(const char *val,
}
static Success
convert_to_ulong(const char *val,
unsigned long *res)
{
char *end;
*res = strtoul(val, &end, 10);
if (end == val)
return FAILURE;
while (*end == ' ' || *end == '\t') /* Ignore trailing whitespace. */
end++;
if (*end != '\0')
return FAILURE;
return OK;
}
static Success
assign_text_no(const char *val,
const struct parameter *par)
{
if (val != NULL)
{
long res;
unsigned long res;
if (convert_to_long(val, &res) != OK)
if (convert_to_ulong(val, &res) != OK)
return FAILURE;
*(Text_no*)par->value = res;
......@@ -338,14 +355,16 @@ static Success
assign_ulong(const char *val,
const struct parameter *par)
{
int c;
if (val != NULL)
{
c = (unsigned char)*val;
if ((!isascii(c) || !isdigit(c)) && c != '-')
unsigned long res;
if (convert_to_ulong(val, &res) != OK)
return FAILURE;
*(unsigned long*)par->value = (unsigned long)atol(val);
*(unsigned long*)par->value = res;
/* No need to check for overflow. */
}
return OK;
}
......@@ -354,14 +373,18 @@ static Success
assign_uint(const char *val,
const struct parameter *par)
{
int c;
if (val != NULL)
{
c = (unsigned char)*val;
if ((!isascii(c) || !isdigit(c)) && c != '-')
unsigned long res;
if (convert_to_ulong(val, &res) != OK)
return FAILURE;
*(unsigned int*)par->value = res;
/* Check for overflow. */
if (*(unsigned int*)par->value != res)
return FAILURE;
*(unsigned int*)par->value = (unsigned int)atol(val);
}
return OK;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment