diff options
author | neel <neel@FreeBSD.org> | 2014-03-14 21:35:16 +0000 |
---|---|---|
committer | neel <neel@FreeBSD.org> | 2014-03-14 21:35:16 +0000 |
commit | 79059ce446fd88058babca9eb9b0b3ff2c9e4424 (patch) | |
tree | 63a103f1d987e5c89f26c319b4f10ad89ec20bd6 | |
parent | 4ece58fc6a7c5c9df5d280cb1bbe0b3d6aa2fa57 (diff) | |
download | FreeBSD-src-79059ce446fd88058babca9eb9b0b3ff2c9e4424.zip FreeBSD-src-79059ce446fd88058babca9eb9b0b3ff2c9e4424.tar.gz |
Fix an issue with ktrdump(8) where it would not print all entries in the
KTR buffer.
This happens when 'i' tries to wrap around from 0 to 'entries - 1'. Since 'i'
is a signed integer the modulo operation actually returns a negative number.
Fix this by computing the next index to use "by hand" instead of relying
on the modulo operator.
-rw-r--r-- | usr.bin/ktrdump/ktrdump.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/usr.bin/ktrdump/ktrdump.c b/usr.bin/ktrdump/ktrdump.c index 5f3e7ca..d55aa72 100644 --- a/usr.bin/ktrdump/ktrdump.c +++ b/usr.bin/ktrdump/ktrdump.c @@ -219,8 +219,11 @@ main(int ac, char **av) /* * Now tear through the trace buffer. */ - if (!iflag) - i = (index - 1) % entries; + if (!iflag) { + i = index - 1; + if (i < 0) + i = entries - 1; + } tlast = -1; for (;;) { if (buf[i].ktr_desc == NULL) @@ -288,7 +291,8 @@ next: if ((c = *p++) == '\0') if (!iflag) { if (i == index) break; - i = (i - 1) % entries; + if (--i < 0) + i = entries - 1; } else { if (++i == entries) break; |