Browse Source

lib: os: spsc_pbuf: Fix free space calculation

Fixing bug in free space calculation which was assuming 1 byte
padding and not 32 bit word padding. Bug could result in the
data corruption in certain scenario.

Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
pull/48570/head
Krzysztof Chruscinski 3 years ago committed by Anas Nashif
parent
commit
09b41829a8
  1. 2
      lib/os/spsc_pbuf.c

2
lib/os/spsc_pbuf.c

@ -184,7 +184,7 @@ int spsc_pbuf_alloc(struct spsc_pbuf *pb, uint16_t len, char **buf) @@ -184,7 +184,7 @@ int spsc_pbuf_alloc(struct spsc_pbuf *pb, uint16_t len, char **buf)
}
}
} else {
free_space = rd_idx - wr_idx - 1;
free_space = rd_idx - wr_idx - sizeof(uint32_t);
}
len = MIN(len, MAX(free_space - (int32_t)LEN_SZ, 0));

Loading…
Cancel
Save