From 5ed8822f2b3cc95bf7f9bda45bf7b57e8a693f6d Mon Sep 17 00:00:00 2001 From: Christophe Grenier Date: Sat, 15 Nov 2014 12:29:48 +0100 Subject: [PATCH] Turn off various signed/unsigned comparaison warnings --- src/file_au.c | 2 +- src/file_hdf.c | 4 +++- src/file_jpg.c | 4 ++-- src/file_lxo.c | 7 ++++--- src/file_lzh.c | 7 ++----- src/file_mid.c | 4 +++- src/file_par2.c | 2 +- src/file_pdf.c | 4 ++-- src/file_r3d.c | 2 +- src/file_raf.c | 6 +++--- src/file_sig.c | 2 +- src/file_ttf.c | 2 +- src/file_woff.c | 13 +++++++------ src/filegen.h | 2 +- src/geometry.c | 2 +- src/ntfs_dir.c | 2 +- src/texfat.c | 19 ++++++++++--------- src/xfs.c | 6 +++--- 18 files changed, 47 insertions(+), 43 deletions(-) diff --git a/src/file_au.c b/src/file_au.c index 7b8c35fb..44edeb56 100644 --- a/src/file_au.c +++ b/src/file_au.c @@ -66,7 +66,7 @@ static int header_check_au(const unsigned char *buffer, const unsigned int buffe { const struct header_au_s *au=(const struct header_au_s *)buffer; if(memcmp(buffer,au_header,sizeof(au_header))==0 && - be32(au->offset) >= sizeof(struct header_au_s) && + (const uint32_t)be32(au->offset) >= sizeof(struct header_au_s) && be32(au->encoding)>0 && be32(au->encoding)<=27 && be32(au->channels)>0 && be32(au->channels)<=256) { diff --git a/src/file_hdf.c b/src/file_hdf.c index a557667e..fd02b689 100644 --- a/src/file_hdf.c +++ b/src/file_hdf.c @@ -74,6 +74,7 @@ static void file_check_hdf(file_recovery_t *file_recovery) struct ddh_struct ddh; const struct dd_struct *p; unsigned int i; + unsigned int size; if( #ifdef HAVE_FSEEKO fseeko(file_recovery->handle, offset, SEEK_SET) < 0 || @@ -93,7 +94,8 @@ static void file_check_hdf(file_recovery_t *file_recovery) #ifdef DEBUG_HDF log_info("size=%u next=%lu\n", be16(ddh.size), be32(ddh.next)); #endif - for(i=0, p=dd; i < be16(ddh.size); i++,p++) + size=be16(ddh.size); + for(i=0, p=dd; i < size; i++,p++) { #ifdef DEBUG_HDF log_info("tag=0x%04x, ref=%u, offset=%lu, length=%lu\n", diff --git a/src/file_jpg.c b/src/file_jpg.c index c1924052..fcfafcaf 100644 --- a/src/file_jpg.c +++ b/src/file_jpg.c @@ -1299,7 +1299,7 @@ static void jpg_search_marker(file_recovery_t *file_recovery) { FILE* infile=file_recovery->handle; unsigned char buffer[40*8192]; - int nbytes; + size_t nbytes; uint64_t offset; unsigned int i; if(file_recovery->blocksize==0) @@ -1350,7 +1350,7 @@ static uint64_t jpg_check_structure(file_recovery_t *file_recovery, const unsign FILE* infile=file_recovery->handle; unsigned char buffer[40*8192]; uint64_t thumb_offset=0; - int nbytes; + size_t nbytes; file_recovery->extra=0; #ifdef HAVE_FSEEKO if(fseeko(infile, 0, SEEK_SET) < 0) diff --git a/src/file_lxo.c b/src/file_lxo.c index 532414c0..d19493e7 100644 --- a/src/file_lxo.c +++ b/src/file_lxo.c @@ -53,13 +53,14 @@ struct lxo_header static int header_check_lxo(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { const struct lxo_header *header=(const struct lxo_header *)buffer; - if(be32(header->size) +8 < sizeof(struct lxo_header)) + const uint64_t size=be32(header->size) + 8; + if(size < sizeof(struct lxo_header)) return 0; if(buffer[8]=='L' && buffer[9]=='X' && buffer[10]=='O') { reset_file_recovery(file_recovery_new); file_recovery_new->extension=file_hint_lxo.extension; - file_recovery_new->calculated_file_size=be32(header->size)+8; + file_recovery_new->calculated_file_size=size; file_recovery_new->file_check=&file_check_size; file_recovery_new->data_check=&data_check_size; return 1; @@ -68,7 +69,7 @@ static int header_check_lxo(const unsigned char *buffer, const unsigned int buff { reset_file_recovery(file_recovery_new); file_recovery_new->extension="lwo"; - file_recovery_new->calculated_file_size=be32(header->size)+8; + file_recovery_new->calculated_file_size=size; file_recovery_new->file_check=&file_check_size; file_recovery_new->data_check=&data_check_size; return 1; diff --git a/src/file_lzh.c b/src/file_lzh.c index 669b2b2d..86b6f564 100644 --- a/src/file_lzh.c +++ b/src/file_lzh.c @@ -90,7 +90,7 @@ static void file_rename_level0(const char *old_filename) { unsigned char buffer[512]; FILE *file; - int buffer_size; + size_t buffer_size; unsigned int i; const struct lzh_level0 *hdr=(const struct lzh_level0 *)&buffer; if((file=fopen(old_filename, "rb"))==NULL) @@ -118,7 +118,6 @@ static int header_check_lzh(const unsigned char *buffer, const unsigned int buff file_recovery_new->file_rename=&file_rename_level0; return 1; } - break; /* Level 1 */ case 1: { @@ -129,16 +128,14 @@ static int header_check_lzh(const unsigned char *buffer, const unsigned int buff file_recovery_new->extension=file_hint_lzh.extension; return 1; } - break; /* Level 2 */ case 2: { -// const struct lzh_level2 *hdr=(const struct lzh_level2 *)buffer; + // const struct lzh_level2 *hdr=(const struct lzh_level2 *)buffer; reset_file_recovery(file_recovery_new); file_recovery_new->extension=file_hint_lzh.extension; return 1; } - break; } return 0; } diff --git a/src/file_mid.c b/src/file_mid.c index 2c458615..2ea72d68 100644 --- a/src/file_mid.c +++ b/src/file_mid.c @@ -60,6 +60,7 @@ static void file_check_midi(file_recovery_t *file_recovery) const uint64_t fs_org=file_recovery->file_size; struct midi_header hdr; unsigned int i; + unsigned int tracks; uint64_t fs=4+4+6; file_recovery->file_size=0; if( @@ -70,7 +71,8 @@ static void file_check_midi(file_recovery_t *file_recovery) #endif fread(&hdr, sizeof(hdr), 1, file_recovery->handle) != 1) return ; - for(i=0; ijpg_offset)!=0 && be32(raf->jpg_offset)jpg_offset)!=0 && (const uint32_t)be32(raf->jpg_offset)cfa_offset)!=0 && be32(raf->cfa_offset)cfa_offset)!=0 && (const uint32_t)be32(raf->cfa_offset)cfa_header_offset)!=0 && be32(raf->cfa_header_offset)cfa_header_offset)!=0 && (const uint32_t)be32(raf->cfa_header_offset)jpg_offset)+be32(raf->jpg_size); tmp=(uint64_t)be32(raf->cfa_offset)+be32(raf->cfa_size); diff --git a/src/file_sig.c b/src/file_sig.c index 820390d1..565ebd70 100644 --- a/src/file_sig.c +++ b/src/file_sig.c @@ -388,7 +388,7 @@ static void register_header_check_sig(file_stat_t *file_stat) { char *pos; char *buffer; - off_t buffer_size; + size_t buffer_size; struct stat stat_rec; FILE *handle; handle=open_signature_file(); diff --git a/src/file_ttf.c b/src/file_ttf.c index 97265af0..bb15717f 100644 --- a/src/file_ttf.c +++ b/src/file_ttf.c @@ -91,7 +91,7 @@ static int header_check_ttf(const unsigned char *buffer, const unsigned int buff * entrySelector Log2(maximum power of 2 <= numTables). * rangeShift NumTables x 16-searchRange. * */ - if(td_ilog2(numTables) != be16(ttf->entrySelector)) + if(td_ilog2(numTables) != (uint16_t)be16(ttf->entrySelector)) return 0; if((16<entrySelector)) != be16(ttf->searchRange)) return 0; diff --git a/src/file_woff.c b/src/file_woff.c index b267eb69..f40e04be 100644 --- a/src/file_woff.c +++ b/src/file_woff.c @@ -63,20 +63,21 @@ struct WOFFHeader static int header_check_woff(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new) { const struct WOFFHeader *woff=(const struct WOFFHeader *)buffer; - if(be32(woff->length) < sizeof(struct WOFFHeader)) + const uint64_t length=(uint64_t)be32(woff->length); + if((uint32_t)be32(woff->length) < sizeof(struct WOFFHeader)) return 0; - if(be32(woff->metaOffset) > 0 && be32(woff->metaOffset) < sizeof(struct WOFFHeader)) + if((uint32_t)be32(woff->metaOffset) > 0 && (uint32_t)be32(woff->metaOffset) < sizeof(struct WOFFHeader)) return 0; - if(be32(woff->privOffset) > 0 && be32(woff->privOffset) < sizeof(struct WOFFHeader)) + if((uint32_t)be32(woff->privOffset) > 0 && (uint32_t)be32(woff->privOffset) < sizeof(struct WOFFHeader)) return 0; - if(be32(woff->metaOffset) + be32(woff->metaLength)> be32(woff->length) || - be32(woff->privOffset) + be32(woff->privLength)> be32(woff->length)) + if((uint64_t)be32(woff->metaOffset) + (uint64_t)be32(woff->metaLength) > length || + (uint64_t)be32(woff->privOffset) + (uint64_t)be32(woff->privLength) > length) return 0; if(woff->reserved!=0) return 0; reset_file_recovery(file_recovery_new); file_recovery_new->extension=file_hint_woff.extension; - file_recovery_new->calculated_file_size=(uint64_t)be32(woff->length); + file_recovery_new->calculated_file_size=length; file_recovery_new->data_check=&data_check_size; file_recovery_new->file_check=&file_check_size; return 1; diff --git a/src/filegen.h b/src/filegen.h index 2f243da3..c601400e 100644 --- a/src/filegen.h +++ b/src/filegen.h @@ -95,7 +95,7 @@ struct file_hint_struct /* needed by tar header */ const uint64_t max_filesize; const int recover; - const int enable_by_default; + const unsigned int enable_by_default; void (*register_header_check)(file_stat_t *file_stat); }; diff --git a/src/geometry.c b/src/geometry.c index 3a605dbc..e2becc27 100644 --- a/src/geometry.c +++ b/src/geometry.c @@ -38,7 +38,7 @@ #include "geometry.h" #include "autoset.h" -#define MAX_HEADS 255u +#define MAX_HEADS 255 void set_cylinders_from_size_up(disk_t *disk_car) { diff --git a/src/ntfs_dir.c b/src/ntfs_dir.c index 4feec1e6..4a623b11 100644 --- a/src/ntfs_dir.c +++ b/src/ntfs_dir.c @@ -134,7 +134,7 @@ static int index_get_size(ntfs_inode *inode) } #ifdef HAVE_ICONV -static int ntfs_ucstoutf8(iconv_t cd, const ntfschar *ins, int ins_len, char **outs, int outs_len) +static int ntfs_ucstoutf8(iconv_t cd, const ntfschar *ins, const int ins_len, char **outs, const int outs_len) { const char *inp; char *outp; diff --git a/src/texfat.c b/src/texfat.c index 2f890e0f..5b942471 100644 --- a/src/texfat.c +++ b/src/texfat.c @@ -79,6 +79,7 @@ int exFAT_boot_sector(disk_t *disk, partition_t *partition, const int verbose, c unsigned char *buffer_backup_bs; const char *options=""; int rescan=1; + const int size_bs=12 * disk->sector_size; #ifdef HAVE_NCURSES const struct MenuItem menu_exFAT[]= { @@ -91,8 +92,8 @@ int exFAT_boot_sector(disk_t *disk, partition_t *partition, const int verbose, c { 0, NULL, NULL } }; #endif - buffer_bs=(unsigned char*)MALLOC(12 * disk->sector_size); - buffer_backup_bs=(unsigned char*)MALLOC(12 * disk->sector_size); + buffer_bs=(unsigned char*)MALLOC(size_bs); + buffer_backup_bs=(unsigned char*)MALLOC(size_bs); while(1) { @@ -118,10 +119,10 @@ int exFAT_boot_sector(disk_t *disk, partition_t *partition, const int verbose, c log_info("\nexFAT_boot_sector\n"); log_partition(disk,partition); screen_buffer_add("Boot sector\n"); - if(disk->pread(disk, buffer_bs, 12 * disk->sector_size, partition->part_offset) != 12 * disk->sector_size) + if(disk->pread(disk, buffer_bs, size_bs, partition->part_offset) != size_bs) { screen_buffer_add("Bad: can't read exFAT boot record.\n"); - memset(buffer_bs,0,12 * disk->sector_size); + memset(buffer_bs,0,size_bs); } else if(test_EXFAT((const struct exfat_super_block*)buffer_bs, partition)==0) { @@ -132,10 +133,10 @@ int exFAT_boot_sector(disk_t *disk, partition_t *partition, const int verbose, c else screen_buffer_add("Bad\n"); screen_buffer_add("\nBackup boot record\n"); - if(disk->pread(disk, buffer_backup_bs, 12 * disk->sector_size, partition->part_offset + 12 * disk->sector_size) != 12 * disk->sector_size) + if(disk->pread(disk, buffer_backup_bs, size_bs, partition->part_offset + size_bs) != size_bs) { screen_buffer_add("Bad: can't read exFAT backup boot record.\n"); - memset(buffer_backup_bs,0,12 * disk->sector_size); + memset(buffer_backup_bs,0,size_bs); } else if(test_EXFAT((const struct exfat_super_block*)buffer_backup_bs, partition)==0) { @@ -146,7 +147,7 @@ int exFAT_boot_sector(disk_t *disk, partition_t *partition, const int verbose, c else screen_buffer_add("Bad\n"); screen_buffer_add("\n"); - if(memcmp(buffer_bs,buffer_backup_bs,12 * disk->sector_size)==0) + if(memcmp(buffer_bs, buffer_backup_bs, size_bs)==0) { screen_buffer_add("Sectors are identical.\n"); opt_over=0; @@ -210,7 +211,7 @@ int exFAT_boot_sector(disk_t *disk, partition_t *partition, const int verbose, c if(ask_confirmation("Copy original exFAT boot record over backup, confirm ? (Y/N)")!=0) { log_info("copy original superblock over backup boot\n"); - if(disk->pwrite(disk, buffer_bs, 12 * disk->sector_size, partition->part_offset + 12 * disk->sector_size) != 12 * disk->sector_size) + if(disk->pwrite(disk, buffer_bs, size_bs, partition->part_offset + size_bs) != size_bs) { display_message("Write error: Can't overwrite exFAT backup boot record\n"); } @@ -226,7 +227,7 @@ int exFAT_boot_sector(disk_t *disk, partition_t *partition, const int verbose, c log_info("copy backup superblock over main superblock\n"); /* Reset information about backup boot record */ partition->sb_offset=0; - if(disk->pwrite(disk, buffer_backup_bs, 12 * disk->sector_size, partition->part_offset) != 12 * disk->sector_size) + if(disk->pwrite(disk, buffer_backup_bs, size_bs, partition->part_offset) != size_bs) { display_message("Write error: Can't overwrite exFAT main boot record\n"); } diff --git a/src/xfs.c b/src/xfs.c index 59e4f3f9..a5c2e87d 100644 --- a/src/xfs.c +++ b/src/xfs.c @@ -62,9 +62,9 @@ int check_xfs(disk_t *disk_car,partition_t *partition,const int verbose) static int test_xfs(const disk_t *disk_car, const struct xfs_sb *sb, partition_t *partition, const int verbose) { if(sb->sb_magicnum!=be32(XFS_SB_MAGIC) || - be16(sb->sb_sectsize) != (1U << sb->sb_sectlog) || - be32(sb->sb_blocksize) != (1U << sb->sb_blocklog) || - be16(sb->sb_inodesize) != (1U << sb->sb_inodelog)) + (uint16_t)be16(sb->sb_sectsize) != (1U << sb->sb_sectlog) || + (uint32_t)be32(sb->sb_blocksize) != (1U << sb->sb_blocklog) || + (uint16_t)be16(sb->sb_inodesize) != (1U << sb->sb_inodelog)) return 1; switch(be16(sb->sb_versionnum) & XFS_SB_VERSION_NUMBITS) {