Re: dangling else

Riley Williams (rhw@MemAlpha.CX)
Tue, 13 Jul 1999 12:52:18 +0100 (GMT)


Hi Chris.

On Tue, 13 Jul 1999, Chris Atenasio wrote:

> umm... looks like it was already fixed in sparc64

> linux-2.2.10/arch/sparc/mm/fault.c:386

> if(write)
> if(!(vma->vm_flags & VM_WRITE))
> goto bad_area;
> else
> if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
> goto bad_area;

That doesn't do what the indentation suggests, so you may want to
check what is intended. Here's how the compiler would interpret
that:

> if(write)
> if(!(vma->vm_flags & VM_WRITE))
> goto bad_area;
> else
> if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
> goto bad_area;

As you can see, the implications are different. Here's the corrected
version of the original, assuming the indentation shows what is
intended...

> if(write)
> {
> if(!(vma->vm_flags & VM_WRITE))
> goto bad_area;
> }
> else
> if(!(vma->vm_flags & (VM_READ | VM_EXEC)))
> goto bad_area;

Note the extra pair of braces...

Best wishes from Riley.

+----------------------------------------------------------------------+
| There is something frustrating about the quality and speed of Linux |
| development, ie., the quality is too high and the speed is too high, |
| in other words, I can implement this XXXX feature, but I bet someone |
| else has already done so and is just about to release their patch. |
+----------------------------------------------------------------------+
* ftp://ftp.MemAlpha.cx/pub/rhw/Linux
* http://www.MemAlpha.cx/kernel.versions.html

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/