Changeset View
Changeset View
Standalone View
Standalone View
libexec/rtld-elf/rtld.c
| Show First 20 Lines • Show All 6,486 Lines • ▼ Show 20 Lines | parse_integer(const char *str) | ||||
| char c; | char c; | ||||
| orig = str; | orig = str; | ||||
| n = 0; | n = 0; | ||||
| for (c = *str; c != '\0'; c = *++str) { | for (c = *str; c != '\0'; c = *++str) { | ||||
| if (c < '0' || c > '9') | if (c < '0' || c > '9') | ||||
| return (-1); | return (-1); | ||||
| if (n > INT_MAX / RADIX) | |||||
| return (-1); | |||||
| n *= RADIX; | n *= RADIX; | ||||
| if (n > INT_MAX - (c - '0')) | |||||
| return (-1); | |||||
| n += c - '0'; | n += c - '0'; | ||||
| } | } | ||||
| /* Make sure we actually parsed something. */ | /* Make sure we actually parsed something. */ | ||||
| if (str == orig) | if (str == orig) | ||||
| return (-1); | return (-1); | ||||
| return (n); | return (n); | ||||
| } | } | ||||
markj: Can we use the stdckint.h routines instead? There is no libc dependency there. | |||||
Done Inline Actions
You can also avoid the need for wrapping, and avoid unsigned ints, like so: if (n > INT_MAX / 10) return (-1); n *= 10; if (n > INT_MAX - (c - '\0')) return (-1); n += (c - '\0'); No need for stdckint.h then, either. dim: > Can we use the stdckint.h routines instead? There is no libc dependency there.
You can also… | |||||
| static void | static void | ||||
| print_usage(const char *argv0) | print_usage(const char *argv0) | ||||
| { | { | ||||
| rtld_printf( | rtld_printf( | ||||
| "Usage: %s [-h] [-b <exe>] [-d] [-f <FD>] [-p] [--] <binary> [<args>]\n" | "Usage: %s [-h] [-b <exe>] [-d] [-f <FD>] [-p] [--] <binary> [<args>]\n" | ||||
| "\n" | "\n" | ||||
| "Options:\n" | "Options:\n" | ||||
| ▲ Show 20 Lines • Show All 315 Lines • Show Last 20 Lines | |||||
Can we use the stdckint.h routines instead? There is no libc dependency there.