diff --git a/tools/autotools/tsk_comparedir.cpp b/tools/autotools/tsk_comparedir.cpp
index 0ab30faf86af0add76f97ad1d4d858f7f2bbfbf1..db771d88e4c3cfc0aeda4641375fa1ca9bb35140 100644
--- a/tools/autotools/tsk_comparedir.cpp
+++ b/tools/autotools/tsk_comparedir.cpp
@@ -166,18 +166,18 @@ uint8_t
     struct stat status;
 
     strncpy(fullPath, m_lclDir, TSK_CD_BUFSIZE);
-    strncat(fullPath, a_dir, TSK_CD_BUFSIZE-strlen(fullPath));
+    strncat(fullPath, a_dir, TSK_CD_BUFSIZE-strlen(fullPath)-1);
     if ((dp = opendir(fullPath)) == NULL) {
         fprintf(stderr, "Error opening directory");
         return 1;
     }
     while ((dirp = readdir(dp)) != NULL) {
         strncpy(file, a_dir, TSK_CD_BUFSIZE);
-        strncat(file, "/", TSK_CD_BUFSIZE-strlen(file));
-        strncat(file, dirp->d_name, TSK_CD_BUFSIZE-strlen(file));
+        strncat(file, "/", TSK_CD_BUFSIZE-strlen(file)-1);
+        strncat(file, dirp->d_name, TSK_CD_BUFSIZE-strlen(file)-1);
 
         strncpy(fullPath, m_lclDir, TSK_CD_BUFSIZE);
-        strncat(fullPath, file, TSK_CD_BUFSIZE-strlen(fullPath));
+        strncat(fullPath, file, TSK_CD_BUFSIZE-strlen(fullPath)-1);
 
         stat(fullPath, &status);
         if (S_ISDIR(status.st_mode)) {