From 2ba237cd4e4322db53368d1b1d346f7fc3b11be8 Mon Sep 17 00:00:00 2001 From: Kees van Reeuwijk Date: Wed, 27 Jan 2010 10:23:58 +0000 Subject: [PATCH] Fixed a number of uses of uninitialized variables by adding assertions or other sanity checks, code reshuffling, or fixing broken behavior. --- drivers/audio/framework/audio_fw.c | 4 ++-- drivers/floppy/floppy.c | 22 +++++++++++----------- lib/stdio/doprnt.c | 1 + lib/stdio/doscan.c | 1 + servers/ds/store.c | 2 +- servers/hgfs/lookup.c | 3 ++- servers/inet/generic/tcp_send.c | 6 ++++-- servers/inet/sr.c | 1 + servers/ipc/sem.c | 3 +-- servers/is/main.c | 4 ++++ servers/mfs/link.c | 2 ++ servers/pm/alarm.c | 3 +++ servers/rs/service.c | 2 +- servers/vfs/main.c | 1 + 14 files changed, 35 insertions(+), 20 deletions(-) diff --git a/drivers/audio/framework/audio_fw.c b/drivers/audio/framework/audio_fw.c index d70a255f3..7d093b9f1 100644 --- a/drivers/audio/framework/audio_fw.c +++ b/drivers/audio/framework/audio_fw.c @@ -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; } diff --git a/drivers/floppy/floppy.c b/drivers/floppy/floppy.c index 86cd7a882..9d313984f 100644 --- a/drivers/floppy/floppy.c +++ b/drivers/floppy/floppy.c @@ -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); + } } } diff --git a/lib/stdio/doprnt.c b/lib/stdio/doprnt.c index 9c4aba2fe..d1cf1d26c 100644 --- a/lib/stdio/doprnt.c +++ b/lib/stdio/doprnt.c @@ -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); diff --git a/lib/stdio/doscan.c b/lib/stdio/doscan.c index 2c1034e64..a9386a61f 100644 --- a/lib/stdio/doscan.c +++ b/lib/stdio/doscan.c @@ -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 == '+') { diff --git a/servers/ds/store.c b/servers/ds/store.c index 0c478bb5b..b2dac7da6 100644 --- a/servers/ds/store.c +++ b/servers/ds/store.c @@ -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. */ diff --git a/servers/hgfs/lookup.c b/servers/hgfs/lookup.c index 8de9b73b0..bee89d802 100644 --- a/servers/hgfs/lookup.c +++ b/servers/hgfs/lookup.c @@ -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]; diff --git a/servers/inet/generic/tcp_send.c b/servers/inet/generic/tcp_send.c index 3d0be8b31..793cbcd0b 100644 --- a/servers/inet/generic/tcp_send.c +++ b/servers/inet/generic/tcp_send.c @@ -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; diff --git a/servers/inet/sr.c b/servers/inet/sr.c index b659f130f..1fc8e56a3 100644 --- a/servers/inet/sr.c +++ b/servers/inet/sr.c @@ -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; diff --git a/servers/ipc/sem.c b/servers/ipc/sem.c index 5eaf59e7b..f4f3cbc63 100644 --- a/servers/ipc/sem.c +++ b/servers/ipc/sem.c @@ -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; diff --git a/servers/is/main.c b/servers/is/main.c index b1117381c..8e0d71b07 100644 --- a/servers/is/main.c +++ b/servers/is/main.c @@ -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 { diff --git a/servers/mfs/link.c b/servers/mfs/link.c index 5645d9426..5ac8558d2 100644 --- a/servers/mfs/link.c +++ b/servers/mfs/link.c @@ -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) { diff --git a/servers/pm/alarm.c b/servers/pm/alarm.c index 33a44176f..82f4172cb 100644 --- a/servers/pm/alarm.c +++ b/servers/pm/alarm.c @@ -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. */ diff --git a/servers/rs/service.c b/servers/rs/service.c index f84e62afe..599d2719e 100644 --- a/servers/rs/service.c +++ b/servers/rs/service.c @@ -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; diff --git a/servers/vfs/main.c b/servers/vfs/main.c index 4508025d6..8379173de 100644 --- a/servers/vfs/main.c +++ b/servers/vfs/main.c @@ -168,6 +168,7 @@ PUBLIC int main(void) break; default: caught = 0; + error = 0; /* To satisfy lints. */ break; } if(caught) { -- 2.44.0