Bad typecast `(size_t *) &config.chunk_size` to `(long long *)`
The variable chunk_size
, a member of struct config
, is declared as a size_t
variable in wget_options.h
L179-180. A pointer to its place in memory is provided to function parse_numbytes()
in options.c
L1462. For this function, it is assumed that the memory that opt->var
is pointing to has a long long int
value (64 bits, cf. options.c
L337 and L359) which is always true for struct config
members quota
, limit_rate
and start_pos
but not for chunk_size
which is not a long long int
variable. On 32-bit architectures, size_t
has just 32 bits. Depending on the compiler and its optimization strategies, the typecast (long long *) &config.chunk_size
might also comprise the first 32 bits of config.quota
and it could also be misaligned as can be seen here:
options.c:359:28: runtime error: store to misaligned address 0x00c1d26c for type 'long long int', which requires 8 byte alignment
0x00c1d26c: note: pointer points here
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
^
Unexpected error code 1, expected 0 [--chunk-size=3]
I am not suggesting how to fix this bug as there are quite a few ways to do so and I don't know which one you would prefer.