From beef8c2eb1f46e26f843f0b089f5e7f5c7f2aa8a Mon Sep 17 00:00:00 2001 From: Brian Carrier <carrier@sleuthkit.org> Date: Thu, 31 Aug 2017 23:33:11 -0400 Subject: [PATCH] fixed codacy C++ warnings / issues --- bindings/java/jni/dataModel_SleuthkitJNI.cpp | 4 ++-- tests/fs_attrlist_apis.cpp | 6 ++++-- tests/fs_fname_apis.cpp | 9 ++++++--- tools/autotools/tsk_comparedir.cpp | 3 ++- tools/autotools/tsk_recover.cpp | 4 ++-- tools/fstools/ils.cpp | 6 ++++-- tools/hashtools/md5.c | 2 +- tools/hashtools/sha1.c | 2 +- tools/vstools/mmls.cpp | 3 ++- tsk/auto/auto_db.cpp | 11 +++++++---- tsk/auto/db_postgresql.cpp | 5 +++-- tsk/auto/db_sqlite.cpp | 3 ++- tsk/base/tsk_error.c | 2 +- tsk/fs/dcat_lib.c | 2 +- tsk/fs/exfatfs.c | 8 ++++++-- tsk/fs/ext2fs.c | 11 +++++++---- tsk/fs/ext2fs_journal.c | 2 +- tsk/fs/fatfs_dent.cpp | 3 ++- tsk/fs/fatfs_meta.c | 7 ++++--- tsk/fs/fatxxfs.c | 7 ++++--- tsk/fs/ffs.c | 8 ++++---- tsk/fs/fls_lib.c | 10 +++++----- tsk/fs/fs_attr.c | 3 +-- tsk/fs/iso9660.c | 20 +++++++++----------- tsk/fs/ntfs_dent.cpp | 3 ++- tsk/fs/yaffs.cpp | 8 +++++--- tsk/img/raw.c | 5 +++-- 27 files changed, 91 insertions(+), 66 deletions(-) diff --git a/bindings/java/jni/dataModel_SleuthkitJNI.cpp b/bindings/java/jni/dataModel_SleuthkitJNI.cpp index fc9ec672d..12b0aec2a 100644 --- a/bindings/java/jni/dataModel_SleuthkitJNI.cpp +++ b/bindings/java/jni/dataModel_SleuthkitJNI.cpp @@ -170,7 +170,7 @@ static TSK_FS_FILE * castFsFile(JNIEnv * env, jlong ptr) { TSK_FS_FILE *lcl = (TSK_FS_FILE *)ptr; - if (!lcl || lcl->tag != TSK_FS_FILE_TAG) { + if (lcl == NULL || lcl->tag != TSK_FS_FILE_TAG) { setThrowTskCoreError(env, "Invalid FS_FILE object"); return 0; } @@ -200,7 +200,7 @@ static TskCaseDb * castCaseDb(JNIEnv * env, jlong ptr) { TskCaseDb *lcl = ((TskCaseDb *) ptr); - if (!lcl || lcl->m_tag != TSK_CASE_DB_TAG) { + if (lcl == NULL || lcl->m_tag != TSK_CASE_DB_TAG) { setThrowTskCoreError(env, "Invalid TskCaseDb object"); return 0; diff --git a/tests/fs_attrlist_apis.cpp b/tests/fs_attrlist_apis.cpp index caa9cc0e9..db910ac9f 100644 --- a/tests/fs_attrlist_apis.cpp +++ b/tests/fs_attrlist_apis.cpp @@ -314,10 +314,12 @@ main(int argc, char **argv) } s_root = argv[1]; - if (test_fat12()) + if (test_fat12()) { return 1; - if (test_ntfs_fe()) + } + else if (test_ntfs_fe()) { return 1; + } printf("Tests Passed\n"); return 0; diff --git a/tests/fs_fname_apis.cpp b/tests/fs_fname_apis.cpp index 9d8d56e1a..629b080e0 100644 --- a/tests/fs_fname_apis.cpp +++ b/tests/fs_fname_apis.cpp @@ -29,22 +29,25 @@ compare_names(const TSK_FS_NAME * fs_name1, const TSK_FS_NAME * fs_name2, uint8_t a_print) { if (fs_name1->type != fs_name2->type) { - if (a_print) + if (a_print) { fprintf(stderr, "ent type mismatch: %x %x\n", fs_name1->type, fs_name2->type); + } return 1; } if (fs_name1->flags != fs_name2->flags) { - if (a_print) + if (a_print) { fprintf(stderr, "flags mismatch: %x %x\n", fs_name1->flags, fs_name2->flags); + } return 1; } if (fs_name1->meta_addr != fs_name2->meta_addr) { - if (a_print) + if (a_print) { fprintf(stderr, "inode address mismatch: %" PRIuINUM " %" PRIuINUM "\n", fs_name1->meta_addr, fs_name2->meta_addr); + } return 1; } diff --git a/tools/autotools/tsk_comparedir.cpp b/tools/autotools/tsk_comparedir.cpp index c1cf55040..89e2af915 100644 --- a/tools/autotools/tsk_comparedir.cpp +++ b/tools/autotools/tsk_comparedir.cpp @@ -283,8 +283,9 @@ uint8_t if (processLclDir(_TSK_T(""))) return 1; - if (!m_missDirFile) + if (!m_missDirFile) { printf("All files in directory found in image\n"); + } if (m_filesInImg.begin() == m_filesInImg.end()) { printf("All files in image found in directory\n"); diff --git a/tools/autotools/tsk_recover.cpp b/tools/autotools/tsk_recover.cpp index ac9acb1da..ffcba517d 100644 --- a/tools/autotools/tsk_recover.cpp +++ b/tools/autotools/tsk_recover.cpp @@ -172,7 +172,7 @@ uint8_t TskRecover::writeFile(TSK_FS_FILE * a_fs_file, const char *a_path) } BOOL result = CreateDirectoryW((LPCTSTR) path16full, NULL); - if (!result) { + if (result == FALSE) { if (GetLastError() == ERROR_PATH_NOT_FOUND) { fprintf(stderr, "Error Creating Directory (%S)", path16full); return 1; @@ -328,7 +328,7 @@ TSK_RETVAL_ENUM TskRecover::processFile(TSK_FS_FILE * fs_file, const char *path) return TSK_OK; else if ((isNtfsSystemFiles(fs_file, path)) || (isFATSystemFiles(fs_file))) return TSK_OK; - else if ((!fs_file->meta) || (fs_file->meta->size == 0)) + else if ((fs_file->meta == NULL) || (fs_file->meta->size == 0)) return TSK_OK; writeFile(fs_file, path); diff --git a/tools/fstools/ils.cpp b/tools/fstools/ils.cpp index db44c4749..d692e513d 100644 --- a/tools/fstools/ils.cpp +++ b/tools/fstools/ils.cpp @@ -335,11 +335,13 @@ main(int argc, char **argv1) ilast = fs->last_inum; } else { - if (istart < fs->first_inum) + if (istart < fs->first_inum) { istart = fs->first_inum; + } - if (ilast > fs->last_inum) + if (ilast > fs->last_inum) { ilast = fs->last_inum; + } } /* NTFS uses alloc and link different than UNIX so change diff --git a/tools/hashtools/md5.c b/tools/hashtools/md5.c index 082290772..012be035f 100644 --- a/tools/hashtools/md5.c +++ b/tools/hashtools/md5.c @@ -35,13 +35,13 @@ main(argc, argv) { char *myname = argv[0]; char *crunch(); - FILE *fp; if (argc < 2) { printf("%s\n", crunch(stdin)); } else { while (--argc && *++argv) { + FILE *fp; if ((fp = fopen(*argv, "r")) == 0) { fprintf(stderr, "%s: ", myname); perror(*argv); diff --git a/tools/hashtools/sha1.c b/tools/hashtools/sha1.c index 4a3456255..76755d391 100644 --- a/tools/hashtools/sha1.c +++ b/tools/hashtools/sha1.c @@ -76,13 +76,13 @@ main(argc, argv) { char *myname = argv[0]; char *crunch(); - FILE *fp; if (argc < 2) { printf("%s\n", crunch(stdin)); } else { while (--argc && *++argv) { + FILE *fp; if ((fp = fopen(*argv, "r")) == 0) { fprintf(stderr, "%s: ", myname); perror(*argv); diff --git a/tools/vstools/mmls.cpp b/tools/vstools/mmls.cpp index 26ffdc519..c7ad7aa20 100644 --- a/tools/vstools/mmls.cpp +++ b/tools/vstools/mmls.cpp @@ -118,8 +118,9 @@ part_act(TSK_VS_INFO * vs, const TSK_VS_PART_INFO * part, void *ptr) if ((recurse) && (vs->vstype == TSK_VS_TYPE_DOS) && (part->flags == TSK_VS_PART_FLAG_ALLOC)) { - if (recurse_cnt < 64) + if (recurse_cnt < 64) { recurse_list[recurse_cnt++] = part->start * part->vs->block_size; + } } return TSK_WALK_CONT; diff --git a/tsk/auto/auto_db.cpp b/tsk/auto/auto_db.cpp index 539c9f7f4..2f3b078b8 100644 --- a/tsk/auto/auto_db.cpp +++ b/tsk/auto/auto_db.cpp @@ -50,10 +50,12 @@ TskAutoDb::TskAutoDb(TskDb * a_db, TSK_HDB_INFO * a_NSRLDb, TSK_HDB_INFO * a_kno m_imgTransactionOpen = false; m_NSRLDb = a_NSRLDb; m_knownBadDb = a_knownBadDb; - if ((m_NSRLDb) || (m_knownBadDb)) + if ((m_NSRLDb) || (m_knownBadDb)) { m_fileHashFlag = true; - else + } + else { m_fileHashFlag = false; + } m_addFileSystems = true; m_noFatFsOrphans = false; m_addUnallocSpace = false; @@ -64,8 +66,9 @@ TskAutoDb::TskAutoDb(TskDb * a_db, TSK_HDB_INFO * a_NSRLDb, TSK_HDB_INFO * a_kno TskAutoDb::~TskAutoDb() { // if they didn't commit / revert, then revert - if (m_imgTransactionOpen) + if (m_imgTransactionOpen) { revertAddImage(); + } closeImage(); tsk_deinit_lock(&m_curDirPathLock); @@ -373,7 +376,7 @@ TSK_RETVAL_ENUM */ uint8_t TskAutoDb::addFilesInImgToDb() { - if (m_db == NULL || !m_db->isDbOpen()) { + if (m_db == NULL || m_db->isDbOpen() == false) { tsk_error_reset(); tsk_error_set_errno(TSK_ERR_AUTO_DB); tsk_error_set_errstr("addFilesInImgToDb: m_db not open"); diff --git a/tsk/auto/db_postgresql.cpp b/tsk/auto/db_postgresql.cpp index 53fb7985b..b24d4a7b6 100755 --- a/tsk/auto/db_postgresql.cpp +++ b/tsk/auto/db_postgresql.cpp @@ -303,7 +303,7 @@ int TskDbPostgreSQL::attempt_exec(const char *sql, const char *errfmt) */ int TskDbPostgreSQL::isEscapedStringValid(const char *sql_str, const char *orig_str, const char *errfmt){ - if (!sql_str){ + if (sql_str == NULL){ tsk_error_reset(); tsk_error_set_errno(TSK_ERR_AUTO_DB); char * str = PQerrorMessage(conn); @@ -892,8 +892,9 @@ int TskDbPostgreSQL::addFsFile(TSK_FS_FILE * fs_file, { int64_t parObjId = 0; - if (fs_file->name == NULL) + if (fs_file->name == NULL) { return 0; + } // Find the object id for the parent folder. diff --git a/tsk/auto/db_sqlite.cpp b/tsk/auto/db_sqlite.cpp index a2ee8f515..682d3c2b1 100755 --- a/tsk/auto/db_sqlite.cpp +++ b/tsk/auto/db_sqlite.cpp @@ -107,8 +107,9 @@ int char * errmsg; - if (!m_db) + if (m_db == NULL) { return 1; + } if (sqlite3_exec(m_db, sql, callback, callback_arg, &errmsg) != SQLITE_OK) { diff --git a/tsk/base/tsk_error.c b/tsk/base/tsk_error.c index 88fba9e20..4a0cd3fcc 100644 --- a/tsk/base/tsk_error.c +++ b/tsk/base/tsk_error.c @@ -377,10 +377,10 @@ tsk_error_vset_errstr2(const char *format, va_list args) void tsk_error_errstr2_concat(const char *format, ...) { - va_list args; char *errstr2 = tsk_error_get_info()->errstr2; int current_length = (int) (strlen(errstr2) + 1); // +1 for a space if (current_length > 0) { + va_list args; int remaining = TSK_ERROR_STRING_MAX_LENGTH - current_length; errstr2[current_length - 1] = ' '; va_start(args, format); diff --git a/tsk/fs/dcat_lib.c b/tsk/fs/dcat_lib.c index f28d7988f..7034dbaaa 100644 --- a/tsk/fs/dcat_lib.c +++ b/tsk/fs/dcat_lib.c @@ -58,7 +58,6 @@ tsk_fs_blkcat(TSK_FS_INFO * fs, TSK_FS_BLKCAT_FLAG_ENUM lclflags, TSK_DADDR_T addr, TSK_DADDR_T read_num_units) { char *buf; - ssize_t cnt; int i; if (lclflags & TSK_FS_BLKCAT_STAT) { @@ -103,6 +102,7 @@ tsk_fs_blkcat(TSK_FS_INFO * fs, TSK_FS_BLKCAT_FLAG_ENUM lclflags, return 1; for (i = 0; i < read_num_units; i++) { + ssize_t cnt; /* Read the block */ cnt = tsk_fs_read_block(fs, addr + i, buf, fs->block_size); diff --git a/tsk/fs/exfatfs.c b/tsk/fs/exfatfs.c index c0c569446..3694632c3 100755 --- a/tsk/fs/exfatfs.c +++ b/tsk/fs/exfatfs.c @@ -239,7 +239,6 @@ exfatfs_get_alloc_bitmap(FATFS_INFO *a_fatfs) TSK_DADDR_T current_sector = 0; TSK_DADDR_T last_sector_of_data_area = 0; char *sector_buf = NULL; - ssize_t bytes_read = 0; EXFATFS_ALLOC_BITMAP_DIR_ENTRY *dentry = NULL; uint64_t i = 0; uint64_t first_sector_of_alloc_bitmap = 0; @@ -255,6 +254,8 @@ exfatfs_get_alloc_bitmap(FATFS_INFO *a_fatfs) current_sector = a_fatfs->rootsect; last_sector_of_data_area = a_fatfs->firstdatasect + (a_fatfs->clustcnt * a_fatfs->csize) - 1; while (current_sector < last_sector_of_data_area) { + ssize_t bytes_read = 0; + /* Read in a sector from the root directory. The allocation bitmap * directory entries will probably be near the beginning of the * directory, probably in the first sector. */ @@ -558,7 +559,6 @@ exfatfs_find_volume_label_dentry(FATFS_INFO *a_fatfs, TSK_FS_FILE *a_fs_file) TSK_FS_INFO *fs = (TSK_FS_INFO *)a_fatfs; TSK_DADDR_T current_sector = 0; TSK_DADDR_T last_sector_of_data_area = 0; - int8_t sector_is_alloc = 0; char *sector_buf = NULL; ssize_t bytes_read = 0; TSK_INUM_T current_inum = 0; @@ -593,6 +593,8 @@ exfatfs_find_volume_label_dentry(FATFS_INFO *a_fatfs, TSK_FS_FILE *a_fs_file) current_sector = a_fatfs->rootsect; last_sector_of_data_area = a_fatfs->firstdatasect + (a_fatfs->clustcnt * a_fatfs->csize) - 1; while (current_sector < last_sector_of_data_area) { + int8_t sector_is_alloc = 0; + /* Read in a sector from the root directory. The volume label * directory entry will probably be near the beginning of the * directory, probably in the first sector. */ @@ -915,6 +917,7 @@ exfatfs_fsstat_fs_content_info(TSK_FS_INFO *a_fs, FILE *a_hFile) * @param [in] a_fs Generic file system info structure for the file system. * @param [in] a_hFile The file handle. */ +#if 0 static void exfatfs_fsstat_fs_fat_chains_info(TSK_FS_INFO *a_fs, FILE *a_hFile) { @@ -973,6 +976,7 @@ exfatfs_fsstat_fs_fat_chains_info(TSK_FS_INFO *a_fs, FILE *a_hFile) sect_run_start = sect_run_end + 1; } } +#endif /** * \internal diff --git a/tsk/fs/ext2fs.c b/tsk/fs/ext2fs.c index ca13753e0..1fd5e23da 100644 --- a/tsk/fs/ext2fs.c +++ b/tsk/fs/ext2fs.c @@ -908,7 +908,6 @@ ext2fs_inode_walk(TSK_FS_INFO * fs, TSK_INUM_T start_inum, { char *myname = "extXfs_inode_walk"; EXT2FS_INFO *ext2fs = (EXT2FS_INFO *) fs; - EXT2_GRPNUM_T grp_num; TSK_INUM_T inum; TSK_INUM_T end_inum_tmp; TSK_INUM_T ibase = 0; @@ -1002,6 +1001,7 @@ ext2fs_inode_walk(TSK_FS_INFO * fs, TSK_INUM_T start_inum, for (inum = start_inum; inum <= end_inum_tmp; inum++) { int retval; + EXT2_GRPNUM_T grp_num; /* * Be sure to use the proper group descriptor data. XXX Linux inodes @@ -1567,10 +1567,11 @@ ext4_load_attrs_extents(TSK_FS_FILE *fs_file) else if (fs_meta->attr_state == TSK_FS_META_ATTR_ERROR) { return 1; } - else if (fs_meta->attr != NULL) { + + if (fs_meta->attr != NULL) { tsk_fs_attrlist_markunused(fs_meta->attr); } - else if (fs_meta->attr == NULL) { + else { fs_meta->attr = tsk_fs_attrlist_alloc(); } @@ -1706,7 +1707,7 @@ ext4_fsstat_datablock_helper(TSK_FS_INFO * fs, FILE * hFile, uint64_t last_block; ext4fs_gd *ext4_gd = ext2fs->ext4_grp_buf; uint64_t db_offset = 0; - unsigned int num_groups = 0, left_over = 0; + unsigned int left_over = 0; if (ext4_gd == NULL) { return; @@ -1750,6 +1751,8 @@ ext4_fsstat_datablock_helper(TSK_FS_INFO * fs, FILE * hFile, //{ if (i % gpfbg == 0) { if (curr_flex_bg == (num_flex_bg - 1)) { + unsigned int num_groups = 0; + num_groups = (unsigned int) (fs->last_block / tsk_getu32(fs->endian, sb->s_blocks_per_group)); diff --git a/tsk/fs/ext2fs_journal.c b/tsk/fs/ext2fs_journal.c index e9238789a..949245795 100644 --- a/tsk/fs/ext2fs_journal.c +++ b/tsk/fs/ext2fs_journal.c @@ -406,7 +406,6 @@ ext2fs_jentry_walk(TSK_FS_INFO * fs, int flags, /* The descriptor describes the FS blocks that follow it */ else if (big_tsk_getu32(head->entry_type) == EXT2_J_ETYPE_DESC) { ext2fs_journ_dentry *dentry; - ext2fs_journ_head *head2; int unalloc = 0; b_desc_seen = 1; @@ -429,6 +428,7 @@ ext2fs_jentry_walk(TSK_FS_INFO * fs, int flags, while ((uintptr_t) dentry <= ((uintptr_t) head + jinfo->bsize - sizeof(ext2fs_journ_head))) { + ext2fs_journ_head *head2; /* Our counter is over the end of the journ */ diff --git a/tsk/fs/fatfs_dent.cpp b/tsk/fs/fatfs_dent.cpp index 29bbdb561..3e51236cf 100644 --- a/tsk/fs/fatfs_dent.cpp +++ b/tsk/fs/fatfs_dent.cpp @@ -279,10 +279,11 @@ TSK_RETVAL_ENUM size = fs_dir->fs_file->meta->size; len = roundup(size, fatfs->ssize); - if (tsk_verbose) + if (tsk_verbose) { tsk_fprintf(stderr, "%s: Processing directory %" PRIuINUM "\n", func_name, a_addr); + } if (size == 0) { if (tsk_verbose) diff --git a/tsk/fs/fatfs_meta.c b/tsk/fs/fatfs_meta.c index a002ac3f9..d7d9bda85 100755 --- a/tsk/fs/fatfs_meta.c +++ b/tsk/fs/fatfs_meta.c @@ -421,10 +421,11 @@ fatfs_make_data_runs(TSK_FS_FILE * a_fs_file) else if (fs_meta->attr_state == TSK_FS_META_ATTR_ERROR) { return 1; } - else if (fs_meta->attr != NULL) { + + if (fs_meta->attr != NULL) { tsk_fs_attrlist_markunused(fs_meta->attr); } - else if (fs_meta->attr == NULL) { + else { fs_meta->attr = tsk_fs_attrlist_alloc(); } @@ -547,7 +548,6 @@ fatfs_make_data_runs(TSK_FS_FILE * a_fs_file) TSK_DADDR_T sbase; TSK_DADDR_T startclust = clust; TSK_OFF_T recoversize = fs_meta->size; - int retval; TSK_FS_ATTR_RUN *data_run = NULL; TSK_FS_ATTR_RUN *data_run_tmp = NULL; TSK_FS_ATTR_RUN *data_run_head = NULL; @@ -604,6 +604,7 @@ fatfs_make_data_runs(TSK_FS_FILE * a_fs_file) return 1; } else { + int retval; /* If the starting cluster is already allocated then we can't * recover it */ diff --git a/tsk/fs/fatxxfs.c b/tsk/fs/fatxxfs.c index 154e87c20..72e407dec 100755 --- a/tsk/fs/fatxxfs.c +++ b/tsk/fs/fatxxfs.c @@ -155,7 +155,6 @@ fatxxfs_fsstat(TSK_FS_INFO * fs, FILE * hFile) else { char *fat_fsinfo_buf; - FATXXFS_FSINFO *fat_info; if ((fat_fsinfo_buf = (char *) tsk_malloc(sizeof(FATXXFS_FSINFO))) == NULL) { @@ -195,6 +194,7 @@ fatxxfs_fsstat(TSK_FS_INFO * fs, FILE * hFile) /* Process the FS info */ if (tsk_getu16(fs->endian, sb->a.f32.fsinfo)) { + FATXXFS_FSINFO *fat_info; cnt = tsk_fs_read(fs, (TSK_DADDR_T) tsk_getu16(fs->endian, sb->a.f32.fsinfo) * fs->block_size, @@ -439,10 +439,8 @@ fatxxfs_open(FATFS_INFO *fatfs) TSK_FS_INFO *fs = &(fatfs->fs_info); FATXXFS_SB *fatsb = (FATXXFS_SB*)(&fatfs->boot_sector_buffer); int i = 0; - ssize_t cnt = 0; TSK_DADDR_T sectors = 0; TSK_FS_DIR * test_dir1; // Directories used to try opening the root directory - TSK_FS_DIR * test_dir2; // to see if it's the Android FAT version // clean up any error messages that are lying around tsk_error_reset(); @@ -650,6 +648,7 @@ fatxxfs_open(FATFS_INFO *fatfs) uint8_t buf2[512]; int i2; int numDiffs; + ssize_t cnt = 0; cnt = tsk_fs_read(fs, fatfs->firstfatsect * fatfs->ssize, @@ -831,6 +830,8 @@ fatxxfs_open(FATFS_INFO *fatfs) test_dir1 = tsk_fs_dir_open_meta(fs, fs->root_inum); if (test_dir1 != NULL && test_dir1->names_used <= 4){ // At most four automatic directories ($MBR, $FAT1, $FAT1, $OrphanFiles) + TSK_FS_DIR * test_dir2; // to see if it's the Android FAT version + fatfs->subtype = TSK_FATFS_SUBTYPE_ANDROID_1; test_dir2 = tsk_fs_dir_open_meta(fs, fs->root_inum); diff --git a/tsk/fs/ffs.c b/tsk/fs/ffs.c index c000a6f09..4f137236d 100644 --- a/tsk/fs/ffs.c +++ b/tsk/fs/ffs.c @@ -47,7 +47,7 @@ ffs_group_load(FFS_INFO * ffs, FFS_GRPNUM_T grp_num) /* * Sanity check */ - if (grp_num < 0 || grp_num >= ffs->groups_count) { + if (grp_num >= ffs->groups_count) { tsk_error_reset(); tsk_error_set_errno(TSK_ERR_FS_ARG); tsk_error_set_errstr @@ -172,11 +172,11 @@ ffs_dinode_load(FFS_INFO * ffs, TSK_INUM_T inum, ffs_inode * dino_buf) } else { - ssize_t cnt; /* Get the base and offset addr for the inode in the tbl */ addr = itod_lcl(fs, ffs->fs.sb1, inum); if (ffs->itbl_addr != addr) { + ssize_t cnt; cnt = tsk_fs_read_block (fs, addr, ffs->itbl_buf, ffs->ffsbsize_b); if (cnt != ffs->ffsbsize_b) { @@ -846,7 +846,6 @@ ffs_inode_walk(TSK_FS_INFO * fs, TSK_INUM_T start_inum, { char *myname = "ffs_inode_walk"; FFS_INFO *ffs = (FFS_INFO *) fs; - FFS_GRPNUM_T grp_num; ffs_cgd *cg = NULL; TSK_INUM_T inum; unsigned char *inosused = NULL; @@ -936,6 +935,7 @@ ffs_inode_walk(TSK_FS_INFO * fs, TSK_INUM_T start_inum, */ for (inum = start_inum; inum <= end_inum_tmp; inum++) { int retval; + FFS_GRPNUM_T grp_num; /* * Be sure to use the proper cylinder group data. @@ -1883,7 +1883,7 @@ ffs_istat(TSK_FS_INFO * fs, TSK_FS_ISTAT_FLAG_ENUM istat_flags, FILE * hFile, TS tsk_fprintf(hFile, "\nDirect Blocks:\n"); if (istat_flags & TSK_FS_ISTAT_RUNLIST) { - TSK_FS_ATTR * fs_attr_direct = tsk_fs_file_attr_get_type(fs_file, + const TSK_FS_ATTR * fs_attr_direct = tsk_fs_file_attr_get_type(fs_file, TSK_FS_ATTR_TYPE_DEFAULT, 0, 0); if (fs_attr_direct && (fs_attr_direct->flags & TSK_FS_ATTR_NONRES)) { if (tsk_fs_attr_print(fs_attr_direct, hFile)) { diff --git a/tsk/fs/fls_lib.c b/tsk/fs/fls_lib.c index b500e0e5a..c8ae5b901 100644 --- a/tsk/fs/fls_lib.c +++ b/tsk/fs/fls_lib.c @@ -51,11 +51,11 @@ printit(TSK_FS_FILE * fs_file, const char *a_path, const TSK_FS_ATTR * fs_attr, const FLS_DATA * fls_data) { TSK_FS_HASH_RESULTS hash_results; - unsigned char null_buf[16]; - unsigned int i; if ((!(fls_data->flags & TSK_FS_FLS_FULL)) && (a_path)) { uint8_t printed = 0; + unsigned int i; + // lazy way to find out how many dirs there could be for (i = 0; a_path[i] != '\0'; i++) { if ((a_path[i] == '/') && (i != 0)) { @@ -77,7 +77,8 @@ printit(TSK_FS_FILE * fs_file, const char *a_path, hash_results.md5_digest); tsk_printf("\n"); } - else{ + else { + unsigned char null_buf[16]; // If the hash calculation had errors, pass in a buffer of nulls memset(null_buf, 0, 16); tsk_fs_name_print_mac_md5(stdout, fs_file, a_path, fs_attr, @@ -216,13 +217,12 @@ tsk_fs_fls(TSK_FS_INFO * fs, TSK_FS_FLS_FLAG_ENUM lclflags, #ifdef TSK_WIN32 { - size_t clen; UTF8 *ptr8; UTF16 *ptr16; int retval; if ((tpre != NULL) && (TSTRLEN(tpre) > 0)) { - clen = TSTRLEN(tpre) * 4; + size_t clen = TSTRLEN(tpre) * 4; data.macpre = (char *) tsk_malloc(clen); if (data.macpre == NULL) { return 1; diff --git a/tsk/fs/fs_attr.c b/tsk/fs/fs_attr.c index 8f1edea1e..27649edf3 100644 --- a/tsk/fs/fs_attr.c +++ b/tsk/fs/fs_attr.c @@ -61,9 +61,8 @@ tsk_fs_attr_run_alloc() void tsk_fs_attr_run_free(TSK_FS_ATTR_RUN * fs_attr_run) { - TSK_FS_ATTR_RUN *fs_attr_run_prev; while (fs_attr_run) { - fs_attr_run_prev = fs_attr_run; + TSK_FS_ATTR_RUN *fs_attr_run_prev = fs_attr_run; fs_attr_run = fs_attr_run->next; fs_attr_run_prev->next = NULL; free(fs_attr_run_prev); diff --git a/tsk/fs/iso9660.c b/tsk/fs/iso9660.c index c7b9dc2c2..8232d3e5b 100644 --- a/tsk/fs/iso9660.c +++ b/tsk/fs/iso9660.c @@ -72,10 +72,9 @@ static void iso9660_inode_list_free(TSK_FS_INFO * fs) { ISO_INFO *iso = (ISO_INFO *) fs; - iso9660_inode_node *tmp; while (iso->in_list) { - tmp = iso->in_list; + iso9660_inode_node *tmp = iso->in_list; iso->in_list = iso->in_list->next; free(tmp); } @@ -142,7 +141,6 @@ parse_susp(TSK_FS_INFO * fs, char *buf, int count, FILE * hFile) // read the continued buffer and parse it if ((tsk_getu32(fs->endian, ce->blk_m) < fs->last_block) && (tsk_getu32(fs->endian, ce->offset_m) < fs->block_size)) { - ssize_t cnt; TSK_OFF_T off; char *buf2; @@ -155,7 +153,7 @@ parse_susp(TSK_FS_INFO * fs, char *buf, int count, FILE * hFile) ce->celen_m)); if (buf2 != NULL) { - cnt = + ssize_t cnt = tsk_fs_read(fs, off, buf2, tsk_getu32(fs->endian, ce->celen_m)); if (cnt == tsk_getu32(fs->endian, ce->celen_m)) { @@ -888,7 +886,6 @@ iso9660_load_inodes_pt(ISO_INFO * iso) char fn[ISO9660_MAXNAMLEN_STD + 1]; /* store current directory name */ path_table_rec dir; TSK_OFF_T pt_offs; /* offset of where we are in path table */ - size_t pt_len; /* bytes left in path table */ TSK_OFF_T extent; /* offset of extent for current directory */ ssize_t cnt; uint8_t is_first = 1; @@ -922,6 +919,7 @@ iso9660_load_inodes_pt(ISO_INFO * iso) /* Now look for unique files in the primary descriptors */ for (p = iso->pvd; p != NULL; p = p->next) { + size_t pt_len; /* bytes left in path table */ pt_offs = (TSK_OFF_T) (tsk_getu32(fs->endian, @@ -1128,18 +1126,17 @@ static void iso9660_close(TSK_FS_INFO * fs) { ISO_INFO *iso = (ISO_INFO *) fs; - iso9660_pvd_node *p; - iso9660_svd_node *s; fs->tag = 0; + while (iso->pvd != NULL) { - p = iso->pvd; + iso9660_pvd_node *p = iso->pvd; iso->pvd = iso->pvd->next; free(p); } while (iso->svd != NULL) { - s = iso->svd; + iso9660_svd_node *s = iso->svd; iso->svd = iso->svd->next; free(s); } @@ -1547,11 +1544,12 @@ iso9660_make_data_run(TSK_FS_FILE * a_fs_file) else if (a_fs_file->meta->attr_state == TSK_FS_META_ATTR_ERROR) { return 1; } + // not sure why this would ever happen, but... - else if (a_fs_file->meta->attr != NULL) { + if (a_fs_file->meta->attr != NULL) { tsk_fs_attrlist_markunused(a_fs_file->meta->attr); } - else if (a_fs_file->meta->attr == NULL) { + else { a_fs_file->meta->attr = tsk_fs_attrlist_alloc(); } diff --git a/tsk/fs/ntfs_dent.cpp b/tsk/fs/ntfs_dent.cpp index f1511e4c3..d3c07b43c 100644 --- a/tsk/fs/ntfs_dent.cpp +++ b/tsk/fs/ntfs_dent.cpp @@ -228,8 +228,9 @@ ntfs_parent_act(TSK_FS_FILE * fs_file, void *ptr) fs_name_list = fs_file->meta->name2; while (fs_name_list) { if (ntfs_parent_map_add(ntfs, fs_name_list, - fs_file->meta)) + fs_file->meta)) { return TSK_WALK_ERROR; + } fs_name_list = fs_name_list->next; } return TSK_WALK_CONT; diff --git a/tsk/fs/yaffs.cpp b/tsk/fs/yaffs.cpp index 6d118cb08..3cb74580e 100644 --- a/tsk/fs/yaffs.cpp +++ b/tsk/fs/yaffs.cpp @@ -529,8 +529,9 @@ static TSK_RETVAL_ENUM YaffsCacheVersion *version; for (version = obj->yco_latest; version != NULL; version = version->ycv_prior) { /* Is this an incomplete version? */ - if (version->ycv_header_chunk == NULL) + if (version->ycv_header_chunk == NULL) { continue; + } if (version->ycv_header_chunk->ycc_parent_id == parent_id) { TSK_RETVAL_ENUM result = cb(obj, version, args); @@ -848,7 +849,7 @@ yaffs_validate_integer_field(std::string numStr){ // Test each character for(i = 0;i < numStr.length();i++){ - if(! isdigit(numStr[i])){ + if(isdigit(numStr[i]) == 0){ return 1; } } @@ -1655,8 +1656,9 @@ static uint8_t if (fs_file->meta->name2 == NULL) { if ((fs_file->meta->name2 = (TSK_FS_META_NAME_LIST *) - tsk_malloc(sizeof(TSK_FS_META_NAME_LIST))) == NULL) + tsk_malloc(sizeof(TSK_FS_META_NAME_LIST))) == NULL) { return 1; + } fs_file->meta->name2->next = NULL; } diff --git a/tsk/img/raw.c b/tsk/img/raw.c index 67984e31f..c5ac383ea 100644 --- a/tsk/img/raw.c +++ b/tsk/img/raw.c @@ -273,11 +273,11 @@ raw_read(TSK_IMG_INFO * img_info, TSK_OFF_T offset, char *buf, size_t len) /* read from the next image segment(s) if needed */ if (((TSK_OFF_T) cnt == read_len) && (read_len != len)) { - ssize_t cnt2; len -= read_len; while (len > 0) { + ssize_t cnt2; /* go to the next image segment */ i++; @@ -333,7 +333,6 @@ static void raw_imgstat(TSK_IMG_INFO * img_info, FILE * hFile) { IMG_RAW_INFO *raw_info = (IMG_RAW_INFO *) img_info; - int i; tsk_fprintf(hFile, "IMAGE FILE INFORMATION\n"); tsk_fprintf(hFile, "--------------------------------------------\n"); @@ -341,6 +340,8 @@ raw_imgstat(TSK_IMG_INFO * img_info, FILE * hFile) tsk_fprintf(hFile, "\nSize in bytes: %" PRIuOFF "\n", img_info->size); if (raw_info->img_info.num_img > 1) { + int i; + tsk_fprintf(hFile, "\n--------------------------------------------\n"); tsk_fprintf(hFile, "Split Information:\n"); -- GitLab