diff options
| author | Simon Tatham <anakin@pobox.com> | 2005-10-22 16:38:15 +0000 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2005-10-22 16:38:15 +0000 |
| commit | b44d75aa4e97e9264e585712a8ec5fa757b645ec (patch) | |
| tree | 7dbc77bdb3661c7f3c453e4310cfbcbbd6af630b | |
| parent | b7f192eea34e0bd36abcd457333ab37eb221789f (diff) | |
| download | puzzles-b44d75aa4e97e9264e585712a8ec5fa757b645ec.zip puzzles-b44d75aa4e97e9264e585712a8ec5fa757b645ec.tar.gz puzzles-b44d75aa4e97e9264e585712a8ec5fa757b645ec.tar.bz2 puzzles-b44d75aa4e97e9264e585712a8ec5fa757b645ec.tar.xz | |
Noticed recently that bitcount16() isn't 16-bit clean due to signed
shift right. It doesn't actually matter in the current code since
the input word only ever uses the bottom 9 bits, but if I ever
extended Mines to work in a triangular grid then all 16 bits might
be required. Fix this now, while I'm cleaning things up, so that it
won't bite me unexpectedly in future.
[originally from svn r6415]
| -rw-r--r-- | mines.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -275,14 +275,16 @@ static char *validate_params(game_params *params, int full) /* * Count the bits in a word. Only needs to cope with 16 bits. */ -static int bitcount16(int word) +static int bitcount16(int inword) { + unsigned int word = inword; + word = ((word & 0xAAAA) >> 1) + (word & 0x5555); word = ((word & 0xCCCC) >> 2) + (word & 0x3333); word = ((word & 0xF0F0) >> 4) + (word & 0x0F0F); word = ((word & 0xFF00) >> 8) + (word & 0x00FF); - return word; + return (int)word; } /* |