U
Udyant Wig
| His code initialized the memory as follows:
| /* Clear second bit */
| *cell &= ~0x02;
| /* Set second bit randomly */
| *cell |= ((byte) (rand () % 2)) << 1;
|
| Since *cell has the type "unsigned char", it cannot have a trap
| representation. Therefore, in the original version of his code, if the
| use of uninitialized memory had been intentional (perhaps as some
| bizarre substitute for proper randomization?), such code would make
| sense. However, since he's corrected the code to memset() the entire
| lattice (presumably to 0), this code is overly complicated. The second
| bit doesn't need to be cleared, because it's already guaranteed to be
| clear. The "|" in the "|=" is unnecessary, because the original value
| was already 0. Therefore, those two lines can be simplified to:
|
| *cell = ((byte) (rand () % 2)) << 1;
|
| And that change, in turn, renders the memset() unnecessary, since the
| result no longer depends, in any way, upon the pre-existing value of
| *cell.
The changes have been made. The initialization code now does only one
thing: initialization of the memory allocated by allocate_lattice().
| /* Clear second bit */
| *cell &= ~0x02;
| /* Set second bit randomly */
| *cell |= ((byte) (rand () % 2)) << 1;
|
| Since *cell has the type "unsigned char", it cannot have a trap
| representation. Therefore, in the original version of his code, if the
| use of uninitialized memory had been intentional (perhaps as some
| bizarre substitute for proper randomization?), such code would make
| sense. However, since he's corrected the code to memset() the entire
| lattice (presumably to 0), this code is overly complicated. The second
| bit doesn't need to be cleared, because it's already guaranteed to be
| clear. The "|" in the "|=" is unnecessary, because the original value
| was already 0. Therefore, those two lines can be simplified to:
|
| *cell = ((byte) (rand () % 2)) << 1;
|
| And that change, in turn, renders the memset() unnecessary, since the
| result no longer depends, in any way, upon the pre-existing value of
| *cell.
The changes have been made. The initialization code now does only one
thing: initialization of the memory allocated by allocate_lattice().