simsong/frag_find — pull request #1 by ncanceill (2013-06-11 10:05:11+00:00)
Title: Make blocksize a local variable

# Make `blocksize` a local variable

## The bug

In the main file `src/frag_find.cpp`, the block size is handled as a local variable:
````c++
uint32_t blocksize = DEFAULT_BLOCKSIZE;
````

This introduces a bug always reproducible with the standard build `./bootstrap.sh && ./configure && make all`.

### Status

Working on:
* Darwin 12.3 x86_64 (Mac OS 10.8) with g++ 4.2.1
* Linux 3.2 x86_64 (Ubuntu 12.04) with g++ 4.6.3

### Description

Using any block size but 512 bytes leads to inconsistent results

### How to reproduce

Using block size 512:
* Scan something containing a blank block (512 consecutive zero bytes) for a master file (of any size at least the block size) full of zeros.
* Expected/actual behavior: the block size is 512; the blank block is detected.

Using any block size between 4 and 511:
* Scan the same thing containing a blank block (512 consecutive zero bytes) for a master file (of any size at least the block size) full of zeros.
* Expected behavior: at least a blank block is detected.
* Actual behavior: the target (the scanned image file) gets the proper block size, but the master file and the reports get blocksize 512 no matter what; nothing is detected even when the master file is larger than 512 bytes.

## The fix

I fixed it in the brutal simple way: make `blocksize` a local variable everywhere.

### Status

`uint32_t blocksize` is no longer declared in the global scope. Instead, it is now declared in `main()`, and set to `DEFAULT_BLOCKSIZE` like before. After that, it may be set in the option-parsing process like before.

Finally, it has been included as a parameter in all the function signatures where it was needed, all directly or undirectly called from `main()`.

### Side-effects

`blocksize` is actually needed in `read_md5deep`, which used to get called during the option-parsing process. To avoid inconsistencies that could occur if option `-m` was used before option `-b`, an intermediate local variable is now used for `-m` during the option-parsing process.