* src/makeint.h: Declare it.
* src/arscan.c (ar_scan): Replace atoi() calls with make_toui().
Modify some integral types to be more correct.
* src/job.c (load_too_high): Replace atoi() calls with make_toui().
* src/main.c (main): Ditto.
(decode_switches): Ditto.
# endif
#endif
char *namemap = 0;
- int namemap_size = 0;
+ unsigned int namemap_size = 0;
int desc = open (archive, O_RDONLY, 0);
if (desc < 0)
return -1;
while (1)
{
- int nread;
+ ssize_t nread;
struct ar_hdr member_header;
#ifdef AIAMAGBIG
struct ar_hdr_big member_header_big;
&& (name[0] == ' ' || name[0] == '/')
&& namemap != 0)
{
- int name_off = atoi (name + 1);
- int name_len;
+ const char* err;
+ unsigned int name_off = make_toui (name + 1, &err);
+ size_t name_len;
- if (name_off < 0 || name_off >= namemap_size)
+ if (err|| name_off >= namemap_size)
goto invalid;
name = namemap + name_off;
&& name[1] == '1'
&& name[2] == '/')
{
- int name_len = atoi (name + 3);
+ const char* err;
+ unsigned int name_len = make_toui (name + 3, &err);
- if (name_len < 1)
+ if (err || name_len == 0 || name_len > PATH_MAX)
goto invalid;
name = alloca (name_len + 1);
if (p && ISDIGIT(p[1]))
{
- int cnt = atoi (p+1);
- DB (DB_JOBS, ("Running: system = %d / make = %u (max requested = %f)\n",
+ unsigned int cnt = make_toui (p+1, NULL);
+ DB (DB_JOBS, ("Running: system = %u / make = %u (max requested = %f)\n",
cnt, job_slots_used, max_load_average));
return (double)cnt > max_load_average;
}
OUTPUT_TRACED ();
++ep;
}
- restarts = (unsigned int) atoi (ep);
+ restarts = make_toui (ep, NULL);
export = v_noexport;
}
{
struct variable *v = lookup_variable (STRING_SIZE_TUPLE (MAKELEVEL_NAME));
if (v && v->value[0] != '\0' && v->value[0] != '-')
- makelevel = (unsigned int) atoi (v->value);
+ makelevel = make_toui (v->value, NULL);
else
makelevel = 0;
}
if (coptarg)
{
- int i = atoi (coptarg);
- const char *cp;
-
- /* Yes, I realize we're repeating this in some cases. */
- for (cp = coptarg; ISDIGIT (cp[0]); ++cp)
- ;
+ const char *err;
+ unsigned int i = make_toui (coptarg, &err);
- if (i < 1 || cp[0] != '\0')
+ if (err || i == 0)
{
error (NILF, 0,
_("the '-%c' option requires a positive integer argument"),
void pfatal_with_name (const char *) NORETURN;
void perror_with_name (const char *, const char *);
#define xstrlen(_s) ((_s)==NULL ? 0 : strlen (_s))
+unsigned int make_toui (const char*, const char**);
pid_t make_pid ();
void *xmalloc (size_t);
void *xcalloc (size_t);
# include <sys/file.h>
#endif
+unsigned int
+make_toui (const char *str, const char **error)
+{
+ char *end;
+ unsigned long val = strtoul (str, &end, 10);
+
+ if (error)
+ {
+ if (str[0] == '\0')
+ *error = "Missing value";
+ else if (*end != '\0')
+ *error = "Invalid value";
+ else
+ *error = NULL;
+ }
+
+ return val;
+}
+
/* Compare strings *S1 and *S2.
Return negative if the first is less, positive if it is greater,
zero if they are equal. */