Friday challenge 2: spot the bug

David Cantrell david at cantrell.org.uk
Fri Apr 20 13:02:08 BST 2007


>From another mailing list, spot the bug.  This is meant to take an int
in $netmask and count the number of bits so you can construct a
CIDR-style address/bits.

> for ($maskbits = 0, $i = $netmask; $i != 0; ++$maskbits) {
>       if (($i & 0xc0000000) == 0x40000000) {
>               die("Netmask must have contiguous leftmost '1' bits\n");
>       }
>       $i <<= 1;
> }

Yes, it's obviously translated from C.  I'm not after stylistic
criticisms.

I'll post a clue after lunch.

-- 
David Cantrell | Hero of the Information Age

  For every vengeance, there is an equal and opposite revengeance.
                                            -- Cartoon Law X


More information about the london.pm mailing list