From 160402522f253c6153ae2b2dfced2231a7e4f9f7 Mon Sep 17 00:00:00 2001
From: Brian Carrier <carrier@sleuthkit.org>
Date: Mon, 2 Mar 2009 23:16:58 +0000
Subject: [PATCH] Fixed compile warnings reported by Simson Garfinkel

---
 tsk3/fs/dls_lib.c | 16 ++++++++++++++--
 tsk3/fs/fatfs.c   |  4 ++--
 tsk3/fs/ntfs.c    | 16 ++++++++--------
 3 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/tsk3/fs/dls_lib.c b/tsk3/fs/dls_lib.c
index ec25070b6..d47deea56 100644
--- a/tsk3/fs/dls_lib.c
+++ b/tsk3/fs/dls_lib.c
@@ -126,13 +126,25 @@ slack_file_act(TSK_FS_FILE * fs_file, TSK_OFF_T a_off, TSK_DADDR_T addr,
     }
     /* We have passed the end of the allocated space */
     else if (data->flen == 0) {
-        fwrite(buf, size, 1, stdout);
+        if (fwrite(buf, size, 1, stdout) != 1) {
+            tsk_error_reset();
+            tsk_errno = TSK_ERR_FS_WRITE;
+            snprintf(tsk_errstr, TSK_ERRSTR_L,
+                "blkls_lib: error writing to stdout: %s", strerror(errno));
+            return TSK_WALK_ERROR;
+        }
     }
     /* This is the last data unit and there is unused space */
     else if (data->flen < size) {
         /* Clear the used space and print it */
         memset(buf, 0, (size_t) data->flen);
-        fwrite(buf, size, 1, stdout);
+        if (fwrite(buf, size, 1, stdout) != 1) {
+            tsk_error_reset();
+            tsk_errno = TSK_ERR_FS_WRITE;
+            snprintf(tsk_errstr, TSK_ERRSTR_L,
+                "blkls_lib: error writing to stdout: %s", strerror(errno));
+            return TSK_WALK_ERROR;
+        }
         data->flen = 0;
     }
 
diff --git a/tsk3/fs/fatfs.c b/tsk3/fs/fatfs.c
index 35d6d6f35..18cc02122 100644
--- a/tsk3/fs/fatfs.c
+++ b/tsk3/fs/fatfs.c
@@ -778,7 +778,7 @@ fatfs_fsstat(TSK_FS_INFO * fs, FILE * hFile)
                 "Volume Label (Root Directory): %c%c%c%c%c%c%c%c%c%c%c\n",
                 de->name[0], de->name[1], de->name[2], de->name[3],
                 de->name[4], de->name[5], de->name[6], de->name[7],
-                de->name[8], de->name[9], de->name[10]);
+                de->ext[0], de->ext[1], de->ext[2]);
         }
         else {
             tsk_fprintf(hFile, "Volume Label (Root Directory):\n");
@@ -818,7 +818,7 @@ fatfs_fsstat(TSK_FS_INFO * fs, FILE * hFile)
                 "Volume Label (Root Directory): %c%c%c%c%c%c%c%c%c%c%c\n",
                 de->name[0], de->name[1], de->name[2], de->name[3],
                 de->name[4], de->name[5], de->name[6], de->name[7],
-                de->name[8], de->name[9], de->name[10]);
+                de->ext[0], de->ext[1], de->ext[2]);
         }
         else {
             tsk_fprintf(hFile, "Volume Label (Root Directory):\n");
diff --git a/tsk3/fs/ntfs.c b/tsk3/fs/ntfs.c
index 3fd88d4c1..586dd640b 100644
--- a/tsk3/fs/ntfs.c
+++ b/tsk3/fs/ntfs.c
@@ -1618,8 +1618,8 @@ ntfs_proc_attrseq(NTFS_INFO * ntfs,
             }
 
             /* Make sure it is NULL Terminated */
-            else if ((uintptr_t) name8 > (uintptr_t) name + sizeof(name))
-                name[sizeof(name)] = '\0';
+            else if ((uintptr_t) name8 >= (uintptr_t) name + sizeof(name))
+                name[sizeof(name)-1] = '\0';
             else
                 *name8 = '\0';
 
@@ -1992,9 +1992,9 @@ ntfs_proc_attrseq(NTFS_INFO * ntfs,
                 *name8 = '\0';
             }
             /* Make sure it is NULL Terminated */
-            else if ((uintptr_t) name8 >
+            else if ((uintptr_t) name8 >=
                 (uintptr_t) fs_name->name + sizeof(fs_name->name))
-                fs_name->name[sizeof(fs_name->name)] = '\0';
+                fs_name->name[sizeof(fs_name->name)-1] = '\0';
             else
                 *name8 = '\0';
 
@@ -3636,8 +3636,8 @@ ntfs_fsstat(TSK_FS_INFO * fs, FILE * hFile)
         }
 
         /* Make sure it is NULL Terminated */
-        else if ((uintptr_t) name8 > (uintptr_t) asc + sizeof(asc))
-            asc[sizeof(asc)] = '\0';
+        else if ((uintptr_t) name8 >= (uintptr_t) asc + sizeof(asc))
+            asc[sizeof(asc)-1] = '\0';
         else
             *name8 = '\0';
         tsk_fprintf(hFile, "Volume Name: %s\n", asc);
@@ -3719,8 +3719,8 @@ ntfs_fsstat(TSK_FS_INFO * fs, FILE * hFile)
         }
 
         /* Make sure it is NULL Terminated */
-        else if ((uintptr_t) name8 > (uintptr_t) asc + sizeof(asc))
-            asc[sizeof(asc)] = '\0';
+        else if ((uintptr_t) name8 >= (uintptr_t) asc + sizeof(asc))
+            asc[sizeof(asc)-1] = '\0';
         else
             *name8 = '\0';
         tsk_fprintf(hFile, "%s (%" PRIu32 ")   ",
-- 
GitLab