Merge pull request #107 from yamt/shrink-datastream
Shrink struct datastream by borrowing the user buffer
This commit is contained in:
commit
db49540f36
1 changed files with 13 additions and 1 deletions
14
lib/decode.c
14
lib/decode.c
|
@ -399,7 +399,7 @@ static quirc_decode_error_t correct_format(uint16_t *f_ret)
|
|||
*/
|
||||
|
||||
struct datastream {
|
||||
uint8_t raw[QUIRC_MAX_PAYLOAD];
|
||||
uint8_t *raw;
|
||||
int data_bits;
|
||||
int ptr;
|
||||
|
||||
|
@ -905,11 +905,23 @@ quirc_decode_error_t quirc_decode(const struct quirc_code *code,
|
|||
if (err)
|
||||
return err;
|
||||
|
||||
/*
|
||||
* Borrow data->payload to store the raw bits.
|
||||
* It's only used during read_data + coddestream_ecc below.
|
||||
*
|
||||
* This trick saves the size of struct datastream, which we allocate
|
||||
* on the stack.
|
||||
*/
|
||||
|
||||
ds.raw = data->payload;
|
||||
|
||||
read_data(code, data, &ds);
|
||||
err = codestream_ecc(data, &ds);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
ds.raw = NULL; /* We've done with this buffer. */
|
||||
|
||||
err = decode_payload(data, &ds);
|
||||
if (err)
|
||||
return err;
|
||||
|
|
Loading…
Reference in a new issue