Fixed a number of uses of uninitialized variables by adding assertions

or other sanity checks, code reshuffling, or fixing broken behavior.
This commit is contained in:
Kees van Reeuwijk 2010-01-27 10:23:58 +00:00
parent c6eb51d66a
commit 2ba237cd4e
14 changed files with 35 additions and 20 deletions

View file

@ -945,8 +945,8 @@ PRIVATE int init_buffers(sub_dev_t *sub_dev_ptr)
if (!(sub_dev_ptr->ExtraBuf = malloc(sub_dev_ptr->NrOfExtraBuffers *
sub_dev_ptr->DmaSize /
sub_dev_ptr->NrOfDmaFragments))) {
error("%s failed to allocate extra buffer for channel %d\n",
drv.DriverName,i);
error("%s failed to allocate extra buffer for a channel\n",
drv.DriverName);
return EIO;
}

View file

@ -642,18 +642,18 @@ unsigned nr_req; /* length of request vector */
if (*up != NO_OFFSET) break;
fp->fl_sector++;
}
}
if (r == OK && opcode == DEV_SCATTER_S) {
/* Copy the user bytes to the DMA buffer. */
if(proc_nr != SELF) {
s=sys_safecopyfrom(proc_nr, *ug, *up,
(vir_bytes) floppy_buf,
(phys_bytes) SECTOR_SIZE, D);
if(s != OK)
panic("FLOPPY", "sys_safecopyfrom failed", s);
} else {
memcpy(floppy_buf, (void *) (*ug + *up), SECTOR_SIZE);
if (opcode == DEV_SCATTER_S) {
/* Copy the user bytes to the DMA buffer. */
if(proc_nr != SELF) {
s=sys_safecopyfrom(proc_nr, *ug, *up,
(vir_bytes) floppy_buf,
(phys_bytes) SECTOR_SIZE, D);
if(s != OK)
panic("FLOPPY", "sys_safecopyfrom failed", s);
} else {
memcpy(floppy_buf, (void *) (*ug + *up), SECTOR_SIZE);
}
}
}

View file

@ -107,6 +107,7 @@ o_print(va_list *ap, int flags, char *s, char c, int precision, int is_signed)
case 'x':
case 'X':
case 'p': base = 16; break;
default: base = 10; break;
}
s = _i_compute(unsigned_val, base, s, precision);

View file

@ -46,6 +46,7 @@ o_collect(register int c, register FILE *stream, char type,
case 'u': base = 10; break;
case 'o': base = 8; break;
case 'b': base = 2; break;
default: base = 10; break;
}
if (c == '-' || c == '+') {

View file

@ -444,7 +444,7 @@ PUBLIC int do_retrieve(message *m_ptr)
if(!GRANT_VALID(gid))
return -1;
m_ptr->DS_VAL = gid;
m_ptr->DS_VAL_LEN = length;
m_ptr->DS_VAL_LEN = dsp->u.map.length;
}
/* The caller requested a copy of a mapped mem range or a snapshot. */

View file

@ -197,7 +197,8 @@ PUBLIC int do_lookup()
/* Resolve a path string to an inode.
*/
ino_t dir_ino_nr, root_ino_nr;
struct inode *cur_ino, *next_ino, *root_ino;
struct inode *cur_ino, *root_ino;
struct inode *next_ino = NIL_INODE;
struct hgfs_attr attr;
char buf[PATH_MAX], path[PATH_MAX];
char name[NAME_MAX+1];

View file

@ -162,8 +162,8 @@ PRIVATE acc_t *make_pack(tcp_conn)
tcp_conn_t *tcp_conn;
{
acc_t *pack2write, *tmp_pack, *tcp_pack;
tcp_hdr_t *tcp_hdr;
ip_hdr_t *ip_hdr;
tcp_hdr_t *tcp_hdr = NULL;
ip_hdr_t *ip_hdr = NULL;
int tot_hdr_size, ip_hdr_len, no_push, head, more2write;
u32_t seg_seq, seg_lo_data, queue_lo_data, seg_hi, seg_hi_data;
u16_t seg_up, mss;
@ -495,6 +495,8 @@ after_data:
return NULL;
}
assert( tcp_hdr != NULL );
assert( ip_hdr != NULL );
tcp_hdr->th_seq_nr= htonl(seg_seq);
tcp_hdr->th_ack_nr= htonl(tcp_conn->tc_RCV_NXT);
tcp_hdr->th_flags= seg_flags;

View file

@ -176,6 +176,7 @@ mq_t *m;
break;
case DEV_STATUS:
sr_status(&m->mq_mess);
result= OK; /* Satisfy lint. */
send_reply= 0;
free_mess= 1;
break;

View file

@ -446,7 +446,7 @@ PUBLIC int do_semop(message *m)
struct sembuf *sops;
unsigned int nsops;
struct sem_struct *sem;
int no_reply;
int no_reply = 0;
id = m->SEMOP_ID;
nsops = (unsigned int) m->SEMOP_SIZE;
@ -515,7 +515,6 @@ PUBLIC int do_semop(message *m)
}
/* there will be no errors left, so we can go ahead */
no_reply = 0;
for (i = 0; i < nsops; i++) {
struct semaphore *s;
int op_n;

View file

@ -64,6 +64,10 @@ PUBLIC int main(int argc, char **argv)
case TTY_PROC_NR:
result = do_fkey_pressed(&m_in);
break;
default:
/* FIXME: error message. */
result = EDONTREPLY;
break;
}
}
else {

View file

@ -327,6 +327,8 @@ PUBLIC int fs_rename()
if(old_ip != NIL_INODE)
odir = ((old_ip->i_mode & I_TYPE) == I_DIRECTORY); /* TRUE iff dir */
else
odir = FALSE; /* FIXME: is this a safe default? */
/* If it is ok, check for a variety of possible errors. */
if(r == OK) {

View file

@ -143,6 +143,9 @@ PUBLIC int do_itimer()
r = OK;
break;
default:
panic(__FILE__, "invalid timer type", m_in.which_timer);
}
/* If requested, copy the old interval timer to user space. */

View file

@ -1068,7 +1068,7 @@ PRIVATE void do_config(char *label, char *filename)
PUBLIC int main(int argc, char **argv)
{
message m;
int result;
int result = EXIT_SUCCESS;
int request;
int i;
char *label, *progname = NULL;

View file

@ -168,6 +168,7 @@ PUBLIC int main(void)
break;
default:
caught = 0;
error = 0; /* To satisfy lints. */
break;
}
if(caught) {