summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrsc <rsc>2007-08-10 17:17:42 +0000
committerrsc <rsc>2007-08-10 17:17:42 +0000
commitdca5b5ca2e3687f27ebf589fe3855966932840d8 (patch)
tree79be03b3d6f950eb8ceb105449674aaa614bd17e
parent6861140a667cd7219cf9bc1e051faadfc8c46c6f (diff)
downloadxv6-labs-dca5b5ca2e3687f27ebf589fe3855966932840d8.tar.gz
xv6-labs-dca5b5ca2e3687f27ebf589fe3855966932840d8.tar.bz2
xv6-labs-dca5b5ca2e3687f27ebf589fe3855966932840d8.zip
avoid assignments in declarations
-rw-r--r--main.c4
-rw-r--r--printf.c17
-rw-r--r--string.c12
-rw-r--r--sysfile.c2
-rw-r--r--trap.c11
-rw-r--r--ulib.c13
-rw-r--r--umalloc.c2
-rw-r--r--usertests.c19
8 files changed, 44 insertions, 36 deletions
diff --git a/main.c b/main.c
index 76e9eeb..10a448e 100644
--- a/main.c
+++ b/main.c
@@ -118,13 +118,13 @@ mpmain(void)
void
process0(void)
{
- struct proc *p0 = &proc[0];
- struct proc *p1;
extern struct spinlock proc_table_lock;
+ struct proc *p0, *p1;
struct trapframe tf;
release(&proc_table_lock);
+ p0 = &proc[0];
p0->cwd = iget(rootdev, 1);
iunlock(p0->cwd);
diff --git a/printf.c b/printf.c
index e013346..0ddd90b 100644
--- a/printf.c
+++ b/printf.c
@@ -11,18 +11,20 @@ putc(int fd, char c)
static void
printint(int fd, int xx, int base, int sgn)
{
+ static char digits[] = "0123456789ABCDEF";
char buf[16];
- char digits[] = "0123456789ABCDEF";
- int i = 0, neg = 0;
+ int i, neg;
uint x;
+ neg = 0;
if(sgn && xx < 0){
neg = 1;
- x = 0 - xx;
+ x = -xx;
} else {
x = xx;
}
+ i = 0;
do {
buf[i++] = digits[x % base];
} while((x /= base) != 0);
@@ -37,9 +39,12 @@ printint(int fd, int xx, int base, int sgn)
void
printf(int fd, char *fmt, ...)
{
- int i, state = 0, c;
- uint *ap = (uint*)(void*)&fmt + 1;
+ char *s;
+ int c, i, state;
+ uint *ap;
+ state = 0;
+ ap = (uint*)(void*)&fmt + 1;
for(i = 0; fmt[i]; i++){
c = fmt[i] & 0xff;
if(state == 0){
@@ -56,7 +61,7 @@ printf(int fd, char *fmt, ...)
printint(fd, *ap, 16, 0);
ap++;
} else if(c == 's'){
- char *s = (char*)*ap;
+ s = (char*)*ap;
ap++;
while(*s != 0){
putc(fd, *s);
diff --git a/string.c b/string.c
index dc73266..a871b68 100644
--- a/string.c
+++ b/string.c
@@ -4,8 +4,9 @@
void*
memset(void *dst, int c, uint n)
{
- char *d = (char*) dst;
+ char *d;
+ d = (char*)dst;
while(n-- > 0)
*d++ = c;
@@ -15,12 +16,13 @@ memset(void *dst, int c, uint n)
int
memcmp(const void *v1, const void *v2, uint n)
{
- const uchar *s1 = (const uchar*) v1;
- const uchar *s2 = (const uchar*) v2;
-
+ const uchar *s1, *s2;
+
+ s1 = v1;
+ s2 = v2;
while(n-- > 0) {
if(*s1 != *s2)
- return (int) *s1 - (int) *s2;
+ return *s1 - *s2;
s1++, s2++;
}
diff --git a/sysfile.c b/sysfile.c
index a73f250..e5d4eae 100644
--- a/sysfile.c
+++ b/sysfile.c
@@ -54,7 +54,7 @@ int
sys_pipe(void)
{
int *fd;
- struct file *rf = 0, *wf = 0;
+ struct file *rf, *wf;
int fd0, fd1;
if(argptr(0, (void*)&fd, 2*sizeof fd[0]) < 0)
diff --git a/trap.c b/trap.c
index 7a47516..ed66e99 100644
--- a/trap.c
+++ b/trap.c
@@ -30,9 +30,7 @@ idtinit(void)
void
trap(struct trapframe *tf)
{
- int v = tf->trapno;
-
- if(v == T_SYSCALL){
+ if(tf->trapno == T_SYSCALL){
if(cp->killed)
proc_exit();
cp->tf = tf;
@@ -47,7 +45,7 @@ trap(struct trapframe *tf)
// during interrupt handler. Decrement before returning.
cpus[cpu()].nlock++;
- switch(v){
+ switch(tf->trapno){
case IRQ_OFFSET + IRQ_TIMER:
lapic_timerintr();
cpus[cpu()].nlock--;
@@ -82,12 +80,13 @@ trap(struct trapframe *tf)
if(cp) {
// Assume process divided by zero or dereferenced null, etc.
cprintf("pid %d %s: unhandled trap %d on cpu %d eip %x -- kill proc\n",
- cp->pid, cp->name, v, cpu(), tf->eip);
+ cp->pid, cp->name, tf->trapno, cpu(), tf->eip);
proc_exit();
}
// Otherwise it's our mistake.
- cprintf("unexpected trap %d from cpu %d eip %x\n", v, cpu(), tf->eip);
+ cprintf("unexpected trap %d from cpu %d eip %x\n",
+ tf->trapno, cpu(), tf->eip);
panic("trap");
}
diff --git a/ulib.c b/ulib.c
index 994ceb9..6c57b2d 100644
--- a/ulib.c
+++ b/ulib.c
@@ -31,7 +31,8 @@ strcmp(const char *p, const char *q)
uint
strlen(char *s)
{
- int n = 0;
+ int n;
+
for(n = 0; s[n]; n++)
;
return n;
@@ -40,11 +41,11 @@ strlen(char *s)
void*
memset(void *dst, int c, uint n)
{
- char *d = (char*) dst;
-
+ char *d;
+
+ d = dst;
while(n-- > 0)
*d++ = c;
-
return dst;
}
@@ -60,10 +61,10 @@ strchr(const char *s, char c)
char*
gets(char *buf, int max)
{
- int i = 0, cc;
+ int i, cc;
char c;
- while(i+1 < max){
+ for(i=0; i+1 < max; ){
cc = read(0, &c, 1);
if(cc < 1)
break;
diff --git a/umalloc.c b/umalloc.c
index 3473c79..30f970d 100644
--- a/umalloc.c
+++ b/umalloc.c
@@ -19,7 +19,7 @@ union header {
typedef union header Header;
static Header base;
-static Header *freep = 0;
+static Header *freep;
void
free(void *ap)
diff --git a/usertests.c b/usertests.c
index 30673c3..a449ed0 100644
--- a/usertests.c
+++ b/usertests.c
@@ -203,13 +203,14 @@ void
pipe1(void)
{
int fds[2], pid;
- int seq = 0, i, n, cc, total;
+ int seq, i, n, cc, total;
if(pipe(fds) != 0){
printf(1, "pipe() failed\n");
exit();
}
pid = fork();
+ seq = 0;
if(pid == 0){
close(fds[0]);
for(n = 0; n < 5; n++){
@@ -464,8 +465,8 @@ twofiles(void)
void
createdelete(void)
{
+ enum { N = 20 };
int pid, i, fd;
- int n = 20;
char name[32];
printf(1, "createdelete test\n");
@@ -477,7 +478,7 @@ createdelete(void)
name[0] = pid ? 'p' : 'c';
name[2] = '\0';
- for(i = 0; i < n; i++){
+ for(i = 0; i < N; i++){
name[1] = '0' + i;
fd = open(name, O_CREATE | O_RDWR);
if(fd < 0){
@@ -499,14 +500,14 @@ createdelete(void)
// else
//exit();
- for(i = 0; i < n; i++){
+ for(i = 0; i < N; i++){
name[0] = 'p';
name[1] = '0' + i;
fd = open(name, 0);
- if((i == 0 || i >= n/2) && fd < 0){
+ if((i == 0 || i >= N/2) && fd < 0){
printf(1, "oops createdelete %s didn't exist\n", name);
exit();
- } else if((i >= 1 && i < n/2) && fd >= 0){
+ } else if((i >= 1 && i < N/2) && fd >= 0){
printf(1, "oops createdelete %s did exist\n", name);
exit();
}
@@ -516,10 +517,10 @@ createdelete(void)
name[0] = 'c';
name[1] = '0' + i;
fd = open(name, 0);
- if((i == 0 || i >= n/2) && fd < 0){
+ if((i == 0 || i >= N/2) && fd < 0){
printf(1, "oops createdelete %s didn't exist\n", name);
exit();
- } else if((i >= 1 && i < n/2) && fd >= 0){
+ } else if((i >= 1 && i < N/2) && fd >= 0){
printf(1, "oops createdelete %s did exist\n", name);
exit();
}
@@ -527,7 +528,7 @@ createdelete(void)
close(fd);
}
- for(i = 0; i < n; i++){
+ for(i = 0; i < N; i++){
name[0] = 'p';
name[1] = '0' + i;
unlink(name);