Fixed several issues with compat flag parsing

- Fixed issue where some overflowed compat flags could end up ignored.

  A simple typo: incrementing by the unrelated d variable, meant we
  were skipping overflowed compat flags whenever the previous logic sets
  d > 1.

- Fixed issue where any zero padding was treated as overflowed compat
  flags.

  Note this hid the previous issue from our tests.

Added more tests to prevent a regression here. Letting bad compat flag
parsing through would be _very_ annoying in the future.

Code changes:

           code          stack          ctx
  before: 38148           2608          752
  after:  38084 (-0.2%)   2608 (+0.0%)  752 (+0.0%)
This commit is contained in:
Christopher Haster
2025-01-05 00:02:11 -06:00
parent 82d0ffb355
commit ab160d7feb
2 changed files with 124 additions and 9 deletions
+6 -6
View File
@@ -13471,16 +13471,16 @@ static int lfsr_data_readrcompat(lfs_t *lfs, lfsr_data_t *data,
//
// we don't really care about performance here
while (lfsr_data_size(*data) > 0) {
lfs_scmp_t cmp = lfsr_data_cmp(lfs, *data, (uint8_t[]){0}, 1);
if (cmp < 0) {
return cmp;
uint8_t b;
lfs_ssize_t d = lfsr_data_read(lfs, data, &b, 1);
if (d < 0) {
return d;
}
if (cmp != LFS_CMP_EQ) {
if (b != 0x00) {
*rcompat |= LFSR_RCOMPAT_OVERFLOW;
break;
}
*data = LFSR_DATA_SLICE(*data, d, -1);
}
return 0;