summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2007-04-13 16:15:39 +0200
committerTobias Klauser <tklauser@xenon.tklauser.home>2007-04-13 16:15:39 +0200
commitd7a9bccc00f2bc34dacd216ffd1a9bfa3bfa39fa (patch)
treed92c677d102dff6fd2808b08882ab806dc16e768
parent261e3aecf11ea4b1c095fa728928504c70e97afe (diff)
inotail.c: Fix an integer underflow in bytes_to_offset()
This also caused the bug that nothing was printed when a number greater than the number of characters in the file was specifed with the -c parameter.
-rw-r--r--inotail.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/inotail.c b/inotail.c
index 006f28f..0c278e2 100644
--- a/inotail.c
+++ b/inotail.c
@@ -198,8 +198,9 @@ static off_t lines_to_offset(struct file_struct *f, unsigned long n_lines)
static off_t bytes_to_offset(struct file_struct *f, unsigned long n_bytes)
{
- /* tail everything for 'inotail -c +0' */
- if (from_begin && n_bytes == 0)
+ /* tail everything for 'inotail -c +0' or if n_bytes greater than the
+ * total amount of chars in the file */
+ if ((from_begin && n_bytes == 0) || ((off_t) n_bytes > f->st_size))
return 0;
else
return (from_begin ? ((off_t) n_bytes - 1) : (f->st_size - (off_t) n_bytes));