Skip to content

Commit

Permalink
avoid assignments in declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
rsc committed Aug 10, 2007
1 parent 6861140 commit dca5b5c
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 36 deletions.
4 changes: 2 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
17 changes: 11 additions & 6 deletions printf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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){
Expand All @@ -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);
Expand Down
12 changes: 7 additions & 5 deletions string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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++;
}

Expand Down
2 changes: 1 addition & 1 deletion sysfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 5 additions & 6 deletions trap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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--;
Expand Down Expand Up @@ -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");
}

Expand Down
13 changes: 7 additions & 6 deletions ulib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion umalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ union header {
typedef union header Header;

static Header base;
static Header *freep = 0;
static Header *freep;

void
free(void *ap)
Expand Down
19 changes: 10 additions & 9 deletions usertests.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++){
Expand Down Expand Up @@ -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");
Expand All @@ -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){
Expand All @@ -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();
}
Expand All @@ -516,18 +517,18 @@ 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();
}
if(fd >= 0)
close(fd);
}

for(i = 0; i < n; i++){
for(i = 0; i < N; i++){
name[0] = 'p';
name[1] = '0' + i;
unlink(name);
Expand Down

0 comments on commit dca5b5c

Please sign in to comment.