Limit the scope of several variables
This commit is contained in:
parent
8a36ff31fd
commit
9d0ddd4ce3
9 changed files with 82 additions and 78 deletions
|
@ -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; (i<lng/0x10)&&((i-pos)<EDIT_MAX_LINES); i++)
|
||||
{
|
||||
wmove(stdscr,EDIT_Y+i-pos,EDIT_X);
|
||||
|
|
|
@ -245,14 +245,14 @@ unsigned int get_next_cluster(disk_t *disk_car,const partition_t *partition, con
|
|||
/* Offset can be offset to FAT1 or to FAT2 */
|
||||
/* log_trace("get_next_cluster(upart_type=%u,offset=%u,cluster=%u\n",upart_type,offset,cluster); */
|
||||
unsigned char *buffer;
|
||||
unsigned int next_cluster;
|
||||
unsigned long int offset_s,offset_o;
|
||||
const unsigned int buffer_size=(upart_type==UP_FAT12?2*disk_car->sector_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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
6
src/md.c
6
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 (",
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
126
src/ntfs.c
126
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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++)
|
||||
|
|
|
@ -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)<DIR_NAME_LEN?MAX_NAME_LEN(DEFAULT_BLOCK_SIZE):DIR_NAME_LEN);
|
||||
memcpy(new_file->name,entry.de_name,thislen);
|
||||
|
|
Loading…
Reference in a new issue