Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/vndcompress Judicious (and justified) casts to avoid...
details: https://anonhg.NetBSD.org/src/rev/204c929b1020
branches: trunk
changeset: 326198:204c929b1020
user: riastradh <riastradh%NetBSD.org@localhost>
date: Wed Jan 22 06:15:31 2014 +0000
description:
Judicious (and justified) casts to avoid signed/unsigned comparisons.
diffstat:
usr.bin/vndcompress/offtab.c | 14 +++++++-------
usr.bin/vndcompress/utils.c | 7 ++++---
2 files changed, 11 insertions(+), 10 deletions(-)
diffs (78 lines):
diff -r 7dded648894c -r 204c929b1020 usr.bin/vndcompress/offtab.c
--- a/usr.bin/vndcompress/offtab.c Wed Jan 22 06:15:22 2014 +0000
+++ b/usr.bin/vndcompress/offtab.c Wed Jan 22 06:15:31 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: offtab.c,v 1.2 2014/01/22 06:15:22 riastradh Exp $ */
+/* $NetBSD: offtab.c,v 1.3 2014/01/22 06:15:31 riastradh Exp $ */
/*-
* Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -110,7 +110,7 @@
__CTASSERT(MAX_N_OFFSETS <= (OFF_MAX / sizeof(uint64_t)));
assert(window_start < offtab->ot_n_offsets);
assert(offtab->ot_fdpos <=
- (OFF_MAX - (window_start * sizeof(uint64_t))));
+ (OFF_MAX - (off_t)(window_start * sizeof(uint64_t))));
assert(ISSET(read_flags, OFFTAB_READ_SEEK) ||
(lseek(offtab->ot_fd, 0, SEEK_CUR) == offtab->ot_fdpos) ||
((lseek(offtab->ot_fd, 0, SEEK_CUR) == -1) && (errno == ESPIPE)));
@@ -172,7 +172,7 @@
__CTASSERT(MAX_N_OFFSETS <= (OFF_MAX / sizeof(uint64_t)));
assert(offtab->ot_window_start < offtab->ot_n_offsets);
assert(offtab->ot_fdpos <=
- (OFF_MAX - (offtab->ot_window_start * sizeof(uint64_t))));
+ (OFF_MAX - (off_t)(offtab->ot_window_start * sizeof(uint64_t))));
const ssize_t n_written = pwrite(offtab->ot_fd, offtab->ot_window,
(window_size * sizeof(uint64_t)),
(offtab->ot_fdpos +
@@ -358,10 +358,10 @@
offtab->ot_window_start = 0;
__CTASSERT(MAX_N_OFFSETS <= (OFF_MAX / sizeof(uint64_t)));
assert(offtab->ot_fdpos <=
- (OFF_MAX - (offtab->ot_n_offsets * sizeof(uint64_t))));
- const off_t first_offset = (offtab->ot_fdpos +
+ (OFF_MAX - (off_t)(offtab->ot_n_offsets * sizeof(uint64_t))));
+ const uint64_t first_offset = (offtab->ot_fdpos +
(offtab->ot_n_offsets * sizeof(uint64_t)));
- assert(first_offset <= UINT64_MAX);
+ assert(first_offset <= OFF_MAX);
offtab->ot_window[0] = htobe64(first_offset);
offtab_write_window(offtab, 0, offtab->ot_n_offsets);
@@ -404,7 +404,7 @@
if (ISSET(flags, OFFTAB_CHECKPOINT_SYNC)) {
__CTASSERT(MAX_N_OFFSETS <= (OFF_MAX / sizeof(uint64_t)));
assert(offtab->ot_fdpos
- <= (OFF_MAX - (n_offsets * sizeof(uint64_t))));
+ <= (OFF_MAX - (off_t)(n_offsets * sizeof(uint64_t))));
if (fsync_range(offtab->ot_fd, (FFILESYNC | FDISKSYNC),
offtab->ot_fdpos,
(offtab->ot_fdpos + (n_offsets * sizeof(uint64_t))))
diff -r 7dded648894c -r 204c929b1020 usr.bin/vndcompress/utils.c
--- a/usr.bin/vndcompress/utils.c Wed Jan 22 06:15:22 2014 +0000
+++ b/usr.bin/vndcompress/utils.c Wed Jan 22 06:15:31 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: utils.c,v 1.3 2014/01/22 06:15:22 riastradh Exp $ */
+/* $NetBSD: utils.c,v 1.4 2014/01/22 06:15:31 riastradh Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: utils.c,v 1.3 2014/01/22 06:15:22 riastradh Exp $");
+__RCSID("$NetBSD: utils.c,v 1.4 2014/01/22 06:15:31 riastradh Exp $");
#include <sys/types.h>
@@ -96,7 +96,8 @@
char *p = buffer, *const end __unused = (p + n);
size_t total_read = 0;
- assert(n <= (OFF_MAX - fdpos));
+ assert(0 <= fdpos);
+ assert(n <= (OFF_MAX - (uintmax_t)fdpos));
while (n > 0) {
assert(total_read <= n);
Home |
Main Index |
Thread Index |
Old Index