View | Details | Raw Unified | Return to bug 191263 | Differences between
and this patch

Collapse All | Expand All

(-)args.c (-35 / +28 lines)
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 == SIZE_MAX)
215
		errx(1, "count cannot be negative");
210
		errc(1, ERANGE, "%s", oper);
216
	if (res == 0)
211
	if (cpy_cnt == 0)
217
		cpy_cnt = (uintmax_t)-1;
212
		cpy_cnt = -1;
218
	else
219
		cpy_cnt = (uintmax_t)res;
220
}
213
}
221
214
222
static void
215
static void
Lines 225-231 Link Here
225
218
226
	files_cnt = get_num(arg);
219
	files_cnt = get_num(arg);
227
	if (files_cnt < 1)
220
	if (files_cnt < 1)
228
		errx(1, "files must be between 1 and %jd", (uintmax_t)-1);
221
		errx(1, "files must be between 1 and %ju", SIZE_MAX);
229
}
222
}
230
223
231
static void
224
static void
Lines 241-254 Link Here
241
static void
234
static void
242
f_ibs(char *arg)
235
f_ibs(char *arg)
243
{
236
{
244
	uintmax_t res;
245
237
246
	if (!(ddflags & C_BS)) {
238
	if (!(ddflags & C_BS)) {
247
		res = get_num(arg);
239
		in.dbsz = get_num(arg);
248
		if (res < 1 || res > SSIZE_MAX)
240
		if (in.dbsz < 1 || in.dbsz > SSIZE_MAX)
249
			errx(1, "ibs must be between 1 and %jd",
241
			errx(1, "ibs must be between 1 and %ju", SSIZE_MAX);
250
			    (intmax_t)SSIZE_MAX);
251
		in.dbsz = (size_t)res;
252
	}
242
	}
253
}
243
}
254
244
Lines 262-275 Link Here
262
static void
252
static void
263
f_obs(char *arg)
253
f_obs(char *arg)
264
{
254
{
265
	uintmax_t res;
266
255
267
	if (!(ddflags & C_BS)) {
256
	if (!(ddflags & C_BS)) {
268
		res = get_num(arg);
257
		out.dbsz = get_num(arg);
269
		if (res < 1 || res > SSIZE_MAX)
258
		if (out.dbsz < 1 || out.dbsz > SSIZE_MAX)
270
			errx(1, "obs must be between 1 and %jd",
259
			errx(1, "obs must be between 1 and %jd", SSIZE_MAX);
271
			    (intmax_t)SSIZE_MAX);
272
		out.dbsz = (size_t)res;
273
	}
260
	}
274
}
261
}
275
262
Lines 378-388 Link Here
378
	uintmax_t num, mult, prevnum;
365
	uintmax_t num, mult, prevnum;
379
	char *expr;
366
	char *expr;
380
367
368
	while (isspace(val[0]))
369
		val++;
370
371
	if (val[0] == '-')
372
		errx(1, "%s: cannot be negative", oper);
373
381
	errno = 0;
374
	errno = 0;
382
	num = strtouq(val, &expr, 0);
375
	num = strtoull(val, &expr, 0);
383
	if (errno != 0)				/* Overflow or underflow. */
376
	if (errno != 0)				/* Overflow or underflow. */
384
		err(1, "%s", oper);
377
		err(1, "%s", oper);
385
	
378
386
	if (expr == val)			/* No valid digits. */
379
	if (expr == val)			/* No valid digits. */
387
		errx(1, "%s: illegal numeric value", oper);
380
		errx(1, "%s: illegal numeric value", oper);
388
381
(-)conv.c (-3 / +3 lines)
Lines 133-139 Link Here
133
	 */
133
	 */
134
	ch = 0;
134
	ch = 0;
135
	for (inp = in.dbp - in.dbcnt, outp = out.dbp; in.dbcnt;) {
135
	for (inp = in.dbp - in.dbcnt, outp = out.dbp; in.dbcnt;) {
136
		maxlen = MIN(cbsz, in.dbcnt);
136
		maxlen = MIN(cbsz, (size_t)in.dbcnt);
137
		if ((t = ctab) != NULL)
137
		if ((t = ctab) != NULL)
138
			for (cnt = 0; cnt < maxlen && (ch = *inp++) != '\n';
138
			for (cnt = 0; cnt < maxlen && (ch = *inp++) != '\n';
139
			    ++cnt)
139
			    ++cnt)
Lines 146-152 Link Here
146
		 * Check for short record without a newline.  Reassemble the
146
		 * Check for short record without a newline.  Reassemble the
147
		 * input block.
147
		 * input block.
148
		 */
148
		 */
149
		if (ch != '\n' && in.dbcnt < cbsz) {
149
		if (ch != '\n' && (size_t)in.dbcnt < cbsz) {
150
			(void)memmove(in.db, in.dbp - in.dbcnt, in.dbcnt);
150
			(void)memmove(in.db, in.dbp - in.dbcnt, in.dbcnt);
151
			break;
151
			break;
152
		}
152
		}
Lines 228-234 Link Here
228
	 * translation has to already be done or we might not recognize the
228
	 * translation has to already be done or we might not recognize the
229
	 * spaces.
229
	 * spaces.
230
	 */
230
	 */
231
	for (inp = in.db; in.dbcnt >= cbsz; inp += cbsz, in.dbcnt -= cbsz) {
231
	for (inp = in.db; (size_t)in.dbcnt >= cbsz; inp += cbsz, in.dbcnt -= cbsz) {
232
		for (t = inp + cbsz - 1; t >= inp && *t == ' '; --t)
232
		for (t = inp + cbsz - 1; t >= inp && *t == ' '; --t)
233
			;
233
			;
234
		if (t >= inp) {
234
		if (t >= inp) {
(-)dd.c (-4 / +4 lines)
Lines 168-177 Link Here
168
	 * record oriented I/O, only need a single buffer.
168
	 * record oriented I/O, only need a single buffer.
169
	 */
169
	 */
170
	if (!(ddflags & (C_BLOCK | C_UNBLOCK))) {
170
	if (!(ddflags & (C_BLOCK | C_UNBLOCK))) {
171
		if ((in.db = malloc(out.dbsz + in.dbsz - 1)) == NULL)
171
		if ((in.db = malloc((size_t)out.dbsz + in.dbsz - 1)) == NULL)
172
			err(1, "input buffer");
172
			err(1, "input buffer");
173
		out.db = in.db;
173
		out.db = in.db;
174
	} else if ((in.db = malloc(MAX(in.dbsz, cbsz) + cbsz)) == NULL ||
174
	} else if ((in.db = malloc(MAX((size_t)in.dbsz, cbsz) + cbsz)) == NULL ||
175
	    (out.db = malloc(out.dbsz + cbsz)) == NULL)
175
	    (out.db = malloc(out.dbsz + cbsz)) == NULL)
176
		err(1, "output buffer");
176
		err(1, "output buffer");
177
177
Lines 343-349 Link Here
343
			++st.in_full;
343
			++st.in_full;
344
344
345
		/* Handle full input blocks. */
345
		/* Handle full input blocks. */
346
		} else if ((size_t)n == in.dbsz) {
346
		} else if ((size_t)n == (size_t)in.dbsz) {
347
			in.dbcnt += in.dbrcnt = n;
347
			in.dbcnt += in.dbrcnt = n;
348
			++st.in_full;
348
			++st.in_full;
349
349
Lines 493-499 Link Here
493
			outp += nw;
493
			outp += nw;
494
			st.bytes += nw;
494
			st.bytes += nw;
495
495
496
			if ((size_t)nw == n && n == out.dbsz)
496
			if ((size_t)nw == n && n == (size_t)out.dbsz)
497
				++st.out_full;
497
				++st.out_full;
498
			else
498
			else
499
				++st.out_part;
499
				++st.out_part;
(-)dd.h (-11 / +10 lines)
Lines 38-47 Link Here
38
typedef struct {
38
typedef struct {
39
	u_char		*db;		/* buffer address */
39
	u_char		*db;		/* buffer address */
40
	u_char		*dbp;		/* current buffer I/O address */
40
	u_char		*dbp;		/* current buffer I/O address */
41
	/* XXX ssize_t? */
41
	ssize_t		dbcnt;		/* current buffer byte count */
42
	size_t		dbcnt;		/* current buffer byte count */
42
	ssize_t		dbrcnt;		/* last read byte count */
43
	size_t		dbrcnt;		/* last read byte count */
43
	ssize_t		dbsz;		/* block size */
44
	size_t		dbsz;		/* block size */
45
44
46
#define	ISCHR		0x01		/* character device (warn on short) */
45
#define	ISCHR		0x01		/* character device (warn on short) */
47
#define	ISPIPE		0x02		/* pipe-like (see position.c) */
46
#define	ISPIPE		0x02		/* pipe-like (see position.c) */
Lines 57-69 Link Here
57
} IO;
56
} IO;
58
57
59
typedef struct {
58
typedef struct {
60
	uintmax_t	in_full;	/* # of full input blocks */
59
	size_t	in_full;	/* # of full input blocks */
61
	uintmax_t	in_part;	/* # of partial input blocks */
60
	size_t	in_part;	/* # of partial input blocks */
62
	uintmax_t	out_full;	/* # of full output blocks */
61
	size_t	out_full;	/* # of full output blocks */
63
	uintmax_t	out_part;	/* # of partial output blocks */
62
	size_t	out_part;	/* # of partial output blocks */
64
	uintmax_t	trunc;		/* # of truncated records */
63
	size_t	trunc;		/* # of truncated records */
65
	uintmax_t	swab;		/* # of odd-length swab blocks */
64
	size_t	swab;		/* # of odd-length swab blocks */
66
	uintmax_t	bytes;		/* # of bytes written */
65
	size_t	bytes;		/* # of bytes written */
67
	struct timespec	start;		/* start time of dd */
66
	struct timespec	start;		/* start time of dd */
68
} STAT;
67
} STAT;
69
68
(-)position.c (-1 / +1 lines)
Lines 178-184 Link Here
178
			n = write(out.fd, out.db, out.dbsz);
178
			n = write(out.fd, out.db, out.dbsz);
179
			if (n == -1)
179
			if (n == -1)
180
				err(1, "%s", out.name);
180
				err(1, "%s", out.name);
181
			if ((size_t)n != out.dbsz)
181
			if (n != out.dbsz)
182
				errx(1, "%s: write failure", out.name);
182
				errx(1, "%s: write failure", out.name);
183
		}
183
		}
184
		break;
184
		break;

Return to bug 191263