Merge pull request #107 from yamt/shrink-datastream

Shrink struct datastream by borrowing the user buffer
This commit is contained in:
Daniel Beer 2021-05-11 10:30:58 +12:00 committed by GitHub
commit db49540f36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -399,7 +399,7 @@ static quirc_decode_error_t correct_format(uint16_t *f_ret)
*/ */
struct datastream { struct datastream {
uint8_t raw[QUIRC_MAX_PAYLOAD]; uint8_t *raw;
int data_bits; int data_bits;
int ptr; int ptr;
@ -905,11 +905,23 @@ quirc_decode_error_t quirc_decode(const struct quirc_code *code,
if (err) if (err)
return 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); read_data(code, data, &ds);
err = codestream_ecc(data, &ds); err = codestream_ecc(data, &ds);
if (err) if (err)
return err; return err;
ds.raw = NULL; /* We've done with this buffer. */
err = decode_payload(data, &ds); err = decode_payload(data, &ds);
if (err) if (err)
return err; return err;