aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/file_wrappers.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2012-06-05 08:59:37 +0000
committerGuy Harris <guy@alum.mit.edu>2012-06-05 08:59:37 +0000
commit00d329575d71d2f0ba8c8838567c63357feab6de (patch)
treed458b3d660c0b8d4f477fc960dd6cdf3c43f3a32 /wiretap/file_wrappers.c
parentaf9f210f5c5323781dc57c3386d76fe1a5ff6959 (diff)
Casting a negative value to unsigned makes it positive; I'm not sure
that will do the right thing here. Instead, cast its negative (which is positive) to unsigned, use that value as the adjustment, and flip the signs of the subsequent adjustment operations. svn path=/trunk/; revision=43105
Diffstat (limited to 'wiretap/file_wrappers.c')
-rw-r--r--wiretap/file_wrappers.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/wiretap/file_wrappers.c b/wiretap/file_wrappers.c
index 300f7348b6..210acc581b 100644
--- a/wiretap/file_wrappers.c
+++ b/wiretap/file_wrappers.c
@@ -928,9 +928,22 @@ file_seek(FILE_T file, gint64 offset, int whence, int *err)
*/
unsigned had = (unsigned)(file->next - file->out);
if (-offset <= had) {
- file->have -= (unsigned)offset;
- file->next += offset;
- file->pos += offset;
+ /*
+ * Offset is negative, so -offset is
+ * non-negative, and -offset is
+ * <= an unsigned and thus fits in an
+ * unsigned. Get that value and
+ * adjust appropriately.
+ *
+ * (Casting offset to unsigned makes
+ * it positive, which is not what we
+ * would want, so we cast -offset
+ * instead.)
+ */
+ unsigned adjustment = (unsigned)(-offset);
+ file->have += adjustment;
+ file->next -= adjustment;
+ file->pos -= adjustment;
return file->pos;
}
}