[ghex/support-block-devices-part-deux: 4/4] hexbufdir: Add warning in helper function
- From: Logan Rathbone <larathbone src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ghex/support-block-devices-part-deux: 4/4] hexbufdir: Add warning in helper function
- Date: Sun, 12 Jun 2022 01:51:59 +0000 (UTC)
commit 78ca3f45cbc941259652c48dd29a58de178a8cfd
Author: Logan Rathbone <poprocks gmail com>
Date: Sat Jun 11 18:30:11 2022 -0400
hexbufdir: Add warning in helper function
ie, requesting data beyond the payload is a programmer error. Luckily
all this reveals is that we're *not* committing that error, but it's a
good sanity check to have in there.
src/hex-buffer-direct.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
---
diff --git a/src/hex-buffer-direct.c b/src/hex-buffer-direct.c
index 23a4ccc..a15ad3a 100644
--- a/src/hex-buffer-direct.c
+++ b/src/hex-buffer-direct.c
@@ -171,6 +171,14 @@ get_file_data (HexBufferDirect *self,
off_t new_offset;
ssize_t nread;
+ if (offset + len > self->payload)
+ {
+ g_critical ("%s: Programmer error - length is past payload. Reducing. "
+ "Some garbage may be displayed in the hex widget.", __func__);
+
+ len = self->payload - offset;
+ }
+
data = g_malloc (len);
new_offset = lseek (self->fd, offset, SEEK_SET);
@@ -179,8 +187,6 @@ get_file_data (HexBufferDirect *self,
errno = 0;
nread = read (self->fd, data, len);
- /* FIXME/TODO - test that if nread is less than amount requested, that it
- * marries up with amount left in payload */
if (nread == -1)
{
set_error (self, _("Failed to read data from file."));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]