|
Lines 41-46
Link Here
|
| 41 |
|
41 |
|
| 42 |
#include <sys/types.h> |
42 |
#include <sys/types.h> |
| 43 |
|
43 |
|
|
|
44 |
#include <ctype.h> |
| 44 |
#include <err.h> |
45 |
#include <err.h> |
| 45 |
#include <errno.h> |
46 |
#include <errno.h> |
| 46 |
#include <inttypes.h> |
47 |
#include <inttypes.h> |
|
Lines 171-178
Link Here
|
| 171 |
*/ |
172 |
*/ |
| 172 |
if (in.offset > OFF_MAX / (ssize_t)in.dbsz || |
173 |
if (in.offset > OFF_MAX / (ssize_t)in.dbsz || |
| 173 |
out.offset > OFF_MAX / (ssize_t)out.dbsz) |
174 |
out.offset > OFF_MAX / (ssize_t)out.dbsz) |
| 174 |
errx(1, "seek offsets cannot be larger than %jd", |
175 |
errx(1, "seek offsets cannot be larger than %jd", OFF_MAX); |
| 175 |
(intmax_t)OFF_MAX); |
|
|
| 176 |
} |
176 |
} |
| 177 |
|
177 |
|
| 178 |
static int |
178 |
static int |
|
Lines 186-222
Link Here
|
| 186 |
static void |
186 |
static void |
| 187 |
f_bs(char *arg) |
187 |
f_bs(char *arg) |
| 188 |
{ |
188 |
{ |
| 189 |
uintmax_t res; |
|
|
| 190 |
|
189 |
|
| 191 |
res = get_num(arg); |
190 |
in.dbsz = out.dbsz = get_num(arg); |
| 192 |
if (res < 1 || res > SSIZE_MAX) |
191 |
if (out.dbsz < 1 || out.dbsz > SSIZE_MAX) |
| 193 |
errx(1, "bs must be between 1 and %jd", (intmax_t)SSIZE_MAX); |
192 |
errx(1, "bs must be between 1 and %jd", SSIZE_MAX); |
| 194 |
in.dbsz = out.dbsz = (size_t)res; |
|
|
| 195 |
} |
193 |
} |
| 196 |
|
194 |
|
| 197 |
static void |
195 |
static void |
| 198 |
f_cbs(char *arg) |
196 |
f_cbs(char *arg) |
| 199 |
{ |
197 |
{ |
| 200 |
uintmax_t res; |
|
|
| 201 |
|
198 |
|
| 202 |
res = get_num(arg); |
199 |
cbsz = get_num(arg); |
| 203 |
if (res < 1 || res > SSIZE_MAX) |
200 |
if (cbsz < 1 || cbsz > SSIZE_MAX) |
| 204 |
errx(1, "cbs must be between 1 and %jd", (intmax_t)SSIZE_MAX); |
201 |
errx(1, "cbs must be between 1 and %jd", SSIZE_MAX); |
| 205 |
cbsz = (size_t)res; |
|
|
| 206 |
} |
202 |
} |
| 207 |
|
203 |
|
| 208 |
static void |
204 |
static void |
| 209 |
f_count(char *arg) |
205 |
f_count(char *arg) |
| 210 |
{ |
206 |
{ |
| 211 |
intmax_t res; |
|
|
| 212 |
|
207 |
|
| 213 |
res = (intmax_t)get_num(arg); |
208 |
cpy_cnt = get_num(arg); |
| 214 |
if (res < 0) |
209 |
if (cpy_cnt == 0) |
| 215 |
errx(1, "count cannot be negative"); |
210 |
cpy_cnt = -1; |
| 216 |
if (res == 0) |
|
|
| 217 |
cpy_cnt = (uintmax_t)-1; |
| 218 |
else |
| 219 |
cpy_cnt = (uintmax_t)res; |
| 220 |
} |
211 |
} |
| 221 |
|
212 |
|
| 222 |
static void |
213 |
static void |
|
Lines 225-231
Link Here
|
| 225 |
|
216 |
|
| 226 |
files_cnt = get_num(arg); |
217 |
files_cnt = get_num(arg); |
| 227 |
if (files_cnt < 1) |
218 |
if (files_cnt < 1) |
| 228 |
errx(1, "files must be between 1 and %jd", (uintmax_t)-1); |
219 |
errx(1, "files must be between 1 and %ju", SIZE_MAX); |
| 229 |
} |
220 |
} |
| 230 |
|
221 |
|
| 231 |
static void |
222 |
static void |
|
Lines 241-254
Link Here
|
| 241 |
static void |
232 |
static void |
| 242 |
f_ibs(char *arg) |
233 |
f_ibs(char *arg) |
| 243 |
{ |
234 |
{ |
| 244 |
uintmax_t res; |
|
|
| 245 |
|
235 |
|
| 246 |
if (!(ddflags & C_BS)) { |
236 |
if (!(ddflags & C_BS)) { |
| 247 |
res = get_num(arg); |
237 |
in.dbsz = get_num(arg); |
| 248 |
if (res < 1 || res > SSIZE_MAX) |
238 |
if (in.dbsz < 1 || in.dbsz > SSIZE_MAX) |
| 249 |
errx(1, "ibs must be between 1 and %jd", |
239 |
errx(1, "ibs must be between 1 and %ju", SSIZE_MAX); |
| 250 |
(intmax_t)SSIZE_MAX); |
|
|
| 251 |
in.dbsz = (size_t)res; |
| 252 |
} |
240 |
} |
| 253 |
} |
241 |
} |
| 254 |
|
242 |
|
|
Lines 262-275
Link Here
|
| 262 |
static void |
250 |
static void |
| 263 |
f_obs(char *arg) |
251 |
f_obs(char *arg) |
| 264 |
{ |
252 |
{ |
| 265 |
uintmax_t res; |
|
|
| 266 |
|
253 |
|
| 267 |
if (!(ddflags & C_BS)) { |
254 |
if (!(ddflags & C_BS)) { |
| 268 |
res = get_num(arg); |
255 |
out.dbsz = get_num(arg); |
| 269 |
if (res < 1 || res > SSIZE_MAX) |
256 |
if (out.dbsz < 1 || out.dbsz > SSIZE_MAX) |
| 270 |
errx(1, "obs must be between 1 and %jd", |
257 |
errx(1, "obs must be between 1 and %jd", SSIZE_MAX); |
| 271 |
(intmax_t)SSIZE_MAX); |
|
|
| 272 |
out.dbsz = (size_t)res; |
| 273 |
} |
258 |
} |
| 274 |
} |
259 |
} |
| 275 |
|
260 |
|
|
Lines 378-388
Link Here
|
| 378 |
uintmax_t num, mult, prevnum; |
363 |
uintmax_t num, mult, prevnum; |
| 379 |
char *expr; |
364 |
char *expr; |
| 380 |
|
365 |
|
|
|
366 |
while (isspace(val[0])) |
| 367 |
val++; |
| 368 |
|
| 369 |
if (val[0] == '-') |
| 370 |
errx(1, "%s: cannot be negative", oper); |
| 371 |
|
| 381 |
errno = 0; |
372 |
errno = 0; |
| 382 |
num = strtouq(val, &expr, 0); |
373 |
num = strtoull(val, &expr, 0); |
| 383 |
if (errno != 0) /* Overflow or underflow. */ |
374 |
if (errno != 0) /* Overflow or underflow. */ |
| 384 |
err(1, "%s", oper); |
375 |
err(1, "%s", oper); |
| 385 |
|
376 |
|
| 386 |
if (expr == val) /* No valid digits. */ |
377 |
if (expr == val) /* No valid digits. */ |
| 387 |
errx(1, "%s: illegal numeric value", oper); |
378 |
errx(1, "%s: illegal numeric value", oper); |
| 388 |
|
379 |
|