From 9d0ddd4ce3471d1f8c15845684df8c19b4876c7c Mon Sep 17 00:00:00 2001 From: Christophe Grenier Date: Tue, 5 May 2009 13:13:14 +0200 Subject: [PATCH] Limit the scope of several variables --- src/edit.c | 4 +- src/fat.c | 8 +++- src/file_7z.c | 4 +- src/file_gz.c | 2 +- src/md.c | 6 ++- src/msdos.c | 2 +- src/ntfs.c | 126 ++++++++++++++++++++++++------------------------- src/parti386.c | 6 +-- src/rfs_dir.c | 2 +- 9 files changed, 82 insertions(+), 78 deletions(-) diff --git a/src/edit.c b/src/edit.c index 46399574..6dfcc774 100644 --- a/src/edit.c +++ b/src/edit.c @@ -197,9 +197,7 @@ static void interface_editor_position(const disk_t *disk_car,uint64_t *lba) static int dump_editor(const unsigned char *nom_dump,const unsigned int lng, const int menu_pos) { - unsigned int i,j; unsigned int pos; - unsigned char car; int done=0; unsigned int menu; struct MenuItem menuDump[]= @@ -217,6 +215,8 @@ static int dump_editor(const unsigned char *nom_dump,const unsigned int lng, con mvwaddstr(stdscr, EDIT_Y, EDIT_X, msg_DUMP_HEXA); do { + unsigned int i,j; + unsigned char car; for (i=pos; (isector_size:disk_car->sector_size); buffer=(unsigned char*)MALLOC(buffer_size); switch(upart_type) { case UP_FAT12: { + unsigned int next_cluster; + unsigned long int offset_s,offset_o; offset_s=(cluster+cluster/2)/disk_car->sector_size; offset_o=(cluster+cluster/2)%disk_car->sector_size; if((unsigned)disk_car->pread(disk_car, buffer, 2 * disk_car->sector_size, @@ -271,6 +271,8 @@ unsigned int get_next_cluster(disk_t *disk_car,const partition_t *partition, con } case UP_FAT16: { + unsigned int next_cluster; + unsigned long int offset_s,offset_o; const uint16_t *p16=(const uint16_t*)buffer; offset_s=cluster/(disk_car->sector_size/2); offset_o=cluster%(disk_car->sector_size/2); @@ -287,6 +289,8 @@ unsigned int get_next_cluster(disk_t *disk_car,const partition_t *partition, con } case UP_FAT32: { + unsigned int next_cluster; + unsigned long int offset_s,offset_o; const uint32_t *p32=(const uint32_t*)buffer; offset_s=cluster/(disk_car->sector_size/4); offset_o=cluster%(disk_car->sector_size/4); diff --git a/src/file_7z.c b/src/file_7z.c index b5809252..d170e94e 100644 --- a/src/file_7z.c +++ b/src/file_7z.c @@ -62,9 +62,9 @@ static void register_header_check_7z(file_stat_t *file_stat) static int header_check_7z(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 header_7z *buffer_7z=(const struct header_7z *)buffer; - if(memcmp(buffer,header_7z,sizeof(header_7z))==0) + if(memcmp(buffer, header_7z, sizeof(header_7z))==0) { + const struct header_7z *buffer_7z=(const struct header_7z *)buffer; reset_file_recovery(file_recovery_new); file_recovery_new->extension=file_hint_7z.extension; file_recovery_new->min_filesize=31; diff --git a/src/file_gz.c b/src/file_gz.c index 2a6c0395..63271115 100644 --- a/src/file_gz.c +++ b/src/file_gz.c @@ -84,7 +84,6 @@ static int header_check_gz(const unsigned char *buffer, const unsigned int buffe { unsigned int off=10; const unsigned int flags=buffer[3]; - int err; /* 4,5,6,7: mtime @@ -119,6 +118,7 @@ static int header_check_gz(const unsigned char *buffer, const unsigned int buffe unsigned char buffer_uncompr[512]; const unsigned int comprLen=(buffer_size<512?buffer_size:512)-off; const unsigned int uncomprLen=512-1; + int err; z_stream d_stream; /* decompression stream */ d_stream.zalloc = (alloc_func)0; d_stream.zfree = (free_func)0; diff --git a/src/md.c b/src/md.c index aab4ae63..217ebe30 100644 --- a/src/md.c +++ b/src/md.c @@ -243,9 +243,9 @@ int recover_MD(disk_t *disk_car, const struct mdp_superblock_s *sb, partition_t static int set_MD_info(const struct mdp_superblock_s *sb, partition_t *partition, const int verbose) { - unsigned int i,d; if(le32(sb->major_version)==0) { + unsigned int i; sprintf(partition->fsname,"md%u",(unsigned int)le32(sb->md_minor)); sprintf(partition->info,"md %u.%u.%u Raid %u: devices", (unsigned int)le32(sb->major_version), @@ -271,6 +271,7 @@ static int set_MD_info(const struct mdp_superblock_s *sb, partition_t *partition } else { + unsigned int i,d; const struct mdp_superblock_1 *sb1=(const struct mdp_superblock_1 *)sb; set_part_name(partition,sb1->set_name,32); sprintf(partition->info,"md %u.x Raid %u - Array Slot : %lu (", @@ -301,9 +302,9 @@ static int set_MD_info(const struct mdp_superblock_s *sb, partition_t *partition static int set_MD_info_be(const struct mdp_superblock_s *sb, partition_t *partition, const int verbose) { - unsigned int i,d; if(be32(sb->major_version)==0) { + unsigned int i; sprintf(partition->fsname,"md%u",(unsigned int)be32(sb->md_minor)); sprintf(partition->info,"md %u.%u.%u Raid %u: devices", (unsigned int)be32(sb->major_version), @@ -329,6 +330,7 @@ static int set_MD_info_be(const struct mdp_superblock_s *sb, partition_t *partit } else { + unsigned int i,d; const struct mdp_superblock_1 *sb1=(const struct mdp_superblock_1 *)sb; set_part_name(partition,sb1->set_name,32); sprintf(partition->info,"md %u.x Raid %u - Array Slot : %lu (", diff --git a/src/msdos.c b/src/msdos.c index 5e85c1f6..7d53f93d 100644 --- a/src/msdos.c +++ b/src/msdos.c @@ -457,12 +457,12 @@ static int disk_pread_aux(disk_t *disk_car, void *buf, const unsigned int count, return -1; } { - unsigned int read_size; uint64_t read_offset=0; do { int i=0; int rc; + unsigned int read_size; read_size=count-read_offset>16*512?16*512:count-read_offset; do { diff --git a/src/ntfs.c b/src/ntfs.c index 2556c4e7..e978523f 100644 --- a/src/ntfs.c +++ b/src/ntfs.c @@ -326,70 +326,68 @@ static int ntfs_get_attr_aux(const char *attr_record, const int my_type, partiti switch(attr_type) { case 0x80: /* AT_DATA */ - { - /* buf must be unsigned! */ - const unsigned char *buf; - uint8_t b; /* Current byte offset in buf. */ - uint16_t mapping_pairs_offset; - const unsigned char*attr_end; /* End of attribute. */ - long lcn; - int64_t deltaxcn = (int64_t)-1; /* Change in [vl]cn. */ - mapping_pairs_offset=NTFS_GETU16(attr_record+32); - buf=(const unsigned char*)attr_record + mapping_pairs_offset; - attr_end = (const unsigned char*)attr_record + attr_len; - lcn = 0; - /* return first element of the run_list */ - { - b = *buf & 0xf; - if (b){ - if (buf + b > attr_end) - { - log_error("Attribut AT_DATA: bad size\n"); - return 0; - } - for (deltaxcn = (int8_t)buf[b--]; b; b--) - deltaxcn = (deltaxcn << 8) + (uint8_t)buf[b]; - /* Assume a negative length to indicate data corruption */ - if (deltaxcn < 0) - log_error("Invalid length in mapping pairs array.\n"); - } else { /* The length entry is compulsory. */ - log_error("Missing length entry in mapping pairs array.\n"); - } - if (deltaxcn >= 0) - { - if (!(*buf & 0xf0)) - { - log_info("LCN_HOLE\n"); - } - else - { - /* Get the lcn change which really can be negative. */ - uint8_t b2 = *buf & 0xf; - b = b2 + ((*buf >> 4) & 0xf); - if (buf + b > attr_end) - { - log_error("Attribut AT_DATA: bad size\n"); - return 0; - } - for (deltaxcn = (int8_t)buf[b--]; b > b2; b--) - deltaxcn = (deltaxcn << 8) + (uint8_t)buf[b]; - /* Change the current lcn to it's new value. */ - lcn += deltaxcn; - /* Check lcn is not below -1. */ - if (lcn < -1) { - log_error("Invalid LCN < -1 in mapping pairs array."); - return 0; - } - if(verbose>1) - { - log_verbose("LCN %ld\n",lcn); - } - if(attr_type==my_type) - return lcn; - } - } - } - } + { + /* buf must be unsigned! */ + const unsigned char *buf; + uint8_t b; /* Current byte offset in buf. */ + uint16_t mapping_pairs_offset; + const unsigned char*attr_end; /* End of attribute. */ + long lcn; + int64_t deltaxcn = (int64_t)-1; /* Change in [vl]cn. */ + mapping_pairs_offset=NTFS_GETU16(attr_record+32); + buf=(const unsigned char*)attr_record + mapping_pairs_offset; + attr_end = (const unsigned char*)attr_record + attr_len; + lcn = 0; + /* return first element of the run_list */ + b = *buf & 0xf; + if (b){ + if (buf + b > attr_end) + { + log_error("Attribut AT_DATA: bad size\n"); + return 0; + } + for (deltaxcn = (int8_t)buf[b--]; b; b--) + deltaxcn = (deltaxcn << 8) + (uint8_t)buf[b]; + /* Assume a negative length to indicate data corruption */ + if (deltaxcn < 0) + log_error("Invalid length in mapping pairs array.\n"); + } else { /* The length entry is compulsory. */ + log_error("Missing length entry in mapping pairs array.\n"); + } + if (deltaxcn >= 0) + { + if (!(*buf & 0xf0)) + { + log_info("LCN_HOLE\n"); + } + else + { + /* Get the lcn change which really can be negative. */ + uint8_t b2 = *buf & 0xf; + b = b2 + ((*buf >> 4) & 0xf); + if (buf + b > attr_end) + { + log_error("Attribut AT_DATA: bad size\n"); + return 0; + } + for (deltaxcn = (int8_t)buf[b--]; b > b2; b--) + deltaxcn = (deltaxcn << 8) + (uint8_t)buf[b]; + /* Change the current lcn to it's new value. */ + lcn += deltaxcn; + /* Check lcn is not below -1. */ + if (lcn < -1) { + log_error("Invalid LCN < -1 in mapping pairs array."); + return 0; + } + if(verbose>1) + { + log_verbose("LCN %ld\n",lcn); + } + if(attr_type==my_type) + return lcn; + } + } + } break; } } diff --git a/src/parti386.c b/src/parti386.c index d69be54a..a6f19821 100644 --- a/src/parti386.c +++ b/src/parti386.c @@ -483,12 +483,12 @@ static list_part_t *get_ext_data_i386(disk_t *disk_car, list_part_t *list_part, { partition_t *partition_ext=partition_main_ext; partition_t *partition_next_ext=NULL; - unsigned int i; unsigned int order=5; do { unsigned char buffer[DEFAULT_SECTOR_SIZE]; int nb_hidden=0, nb_mb=0, nb_part=0, nb_ext=0, nb_boot=0; + unsigned int i; if(disk_car->pread(disk_car, &buffer, sizeof(buffer), partition_ext->part_offset) != sizeof(buffer)) return list_part; if((buffer[0x1FE]!=(unsigned char)0x55)||(buffer[0x1FF]!=(unsigned char)0xAA)) @@ -777,7 +777,6 @@ static int write_all_log_i386(disk_t *disk_car, const list_part_t *list_part, co { for(element=pos_ext->next;(element!=NULL) && (element->part->status==STATUS_LOG);element=element->next) { - int j; unsigned char buffer[DEFAULT_SECTOR_SIZE]; unsigned char buffer_org[DEFAULT_SECTOR_SIZE]; if(verbose>0) @@ -839,6 +838,7 @@ static int write_all_log_i386(disk_t *disk_car, const list_part_t *list_part, co { if(verbose>1) { + int j; for(j=0;j<4;j++) { const struct partition_dos *p=pt_offset(buffer,j); @@ -864,9 +864,9 @@ static int write_all_log_i386(disk_t *disk_car, const list_part_t *list_part, co static int diff(const unsigned char buffer[DEFAULT_SECTOR_SIZE], const unsigned char buffer_org[DEFAULT_SECTOR_SIZE]) { - int j; if(memcmp(buffer,buffer_org,DEFAULT_SECTOR_SIZE)) { + int j; log_info("\nSectors are different.\n"); log_info("buffer_org\n"); for(j=0;j<4;j++) diff --git a/src/rfs_dir.c b/src/rfs_dir.c index 9c76fd2e..70a02ce8 100644 --- a/src/rfs_dir.c +++ b/src/rfs_dir.c @@ -429,7 +429,6 @@ static file_data_t *reiser_dir(disk_t *disk_car, const partition_t *partition, d } while (reiserfs_dir_read(dir, &entry)) { - unsigned int thislen; char name[MAX_NAME_LEN(DEFAULT_BLOCK_SIZE)]; reiserfs_object_t *entity; strncpy(name,dir_data->current_directory,sizeof(name)); @@ -437,6 +436,7 @@ static file_data_t *reiser_dir(disk_t *disk_car, const partition_t *partition, d strcat(name,entry.de_name); if((entity=reiserfs_object_create(ls->current_fs,name,1))) { + unsigned int thislen; file_data_t *new_file=(file_data_t *)MALLOC(sizeof(*new_file)); thislen=(MAX_NAME_LEN(DEFAULT_BLOCK_SIZE)name,entry.de_name,thislen);