diff options
Diffstat (limited to 'libbb/safe_strtol.c')
-rw-r--r-- | libbb/safe_strtol.c | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/libbb/safe_strtol.c b/libbb/safe_strtol.c index a7f012fbc..d3bb29cdd 100644 --- a/libbb/safe_strtol.c +++ b/libbb/safe_strtol.c | |||
@@ -102,40 +102,38 @@ int safe_strtol(const char *arg, long* value) | |||
102 | 102 | ||
103 | # define strong_alias(name, aliasname) _strong_alias (name, aliasname) | 103 | # define strong_alias(name, aliasname) _strong_alias (name, aliasname) |
104 | # define _strong_alias(name, aliasname) \ | 104 | # define _strong_alias(name, aliasname) \ |
105 | __asm__(".global " __C_SYMBOL_PREFIX__ #aliasname "\n" \ | 105 | __asm__(".global " __C_SYMBOL_PREFIX__ #aliasname "\n" \ |
106 | ".set " __C_SYMBOL_PREFIX__ #aliasname "," __C_SYMBOL_PREFIX__ #name); | 106 | ".set " __C_SYMBOL_PREFIX__ #aliasname "," __C_SYMBOL_PREFIX__ #name); |
107 | 107 | ||
108 | #endif | 108 | #endif |
109 | #endif | 109 | #endif |
110 | 110 | ||
111 | int safe_strtoi(const char *arg, int* value) | 111 | int safe_strtoi(const char *arg, int* value) |
112 | { | 112 | { |
113 | if (sizeof(long) == sizeof(int)) { | 113 | int error; |
114 | long lvalue; | ||
115 | if (sizeof(long) == sizeof(int)) | ||
114 | return safe_strtol(arg, (long*)value); | 116 | return safe_strtol(arg, (long*)value); |
115 | } else { | 117 | lvalue = *value; |
116 | int error; | 118 | error = safe_strtol(arg, &lvalue); |
117 | long lvalue = *value; | 119 | if (lvalue < INT_MIN || lvalue > INT_MAX) |
118 | error = safe_strtol(arg, &lvalue); | 120 | return 1; |
119 | if (lvalue < INT_MIN || lvalue > INT_MAX) | 121 | *value = (int) lvalue; |
120 | return 1; | 122 | return error; |
121 | *value = (int) lvalue; | ||
122 | return error; | ||
123 | } | ||
124 | } | 123 | } |
125 | 124 | ||
126 | int safe_strtou(const char *arg, unsigned* value) | 125 | int safe_strtou(const char *arg, unsigned* value) |
127 | { | 126 | { |
128 | if (sizeof(unsigned long) == sizeof(unsigned)) { | 127 | int error; |
128 | unsigned long lvalue; | ||
129 | if (sizeof(unsigned long) == sizeof(unsigned)) | ||
129 | return safe_strtoul(arg, (unsigned long*)value); | 130 | return safe_strtoul(arg, (unsigned long*)value); |
130 | } else { | 131 | lvalue = *value; |
131 | int error; | 132 | error = safe_strtoul(arg, &lvalue); |
132 | unsigned long lvalue = *value; | 133 | if (lvalue > UINT_MAX) |
133 | error = safe_strtoul(arg, &lvalue); | 134 | return 1; |
134 | if (lvalue > UINT_MAX) | 135 | *value = (unsigned) lvalue; |
135 | return 1; | 136 | return error; |
136 | *value = (unsigned) lvalue; | ||
137 | return error; | ||
138 | } | ||
139 | } | 137 | } |
140 | 138 | ||
141 | int BUG_safe_strtou32_unimplemented(void); | 139 | int BUG_safe_strtou32_unimplemented(void); |