zephyr/lib/os
Yasushi SHOJI fedab40576 lib: os: heap-validate: Fix wrong chunkid returned by max_chunkid()
With 64 bytes heap and 1 byte allocation on a big heap, we get:

  0   1   2   3   4   5   6   7
| h | h | b | b | c | 1 | s | f |

where
  - h: chunk0 header
  - b: buckets in chunk0
  - c: chunk header for the first allocation
  - 1: chunk mem
  - s: solo free header
  - f: end marker / footer

max_chunkid() was returning h->end_chunk - min_chunk_size(h), which is
5 because min_chunk_size() on a big heap is 2.  This works if you
don't have the solo free header at 6 and the heap is like:

  0   1   2   3   4   5   6
| h | h | b | b | c | 1 | f |

max_chunkid() in this case gives you 6 - 2 = 4, which is the right
chunkid for the last chunk header.

This commit replaces max_chunkid() with h->end_chunk and "<=" (less
than or equal to) with "<" (less than), so that it always compares
against the end maker chunkid, but the code won't touch the end maker
itself.

Signed-off-by: Yasushi SHOJI <yashi@spacecubics.com>
2021-06-23 06:18:44 -04:00
..
CMakeLists.txt sys: introduce bit arrays 2021-05-07 13:36:22 -04:00
Kconfig lib: os: Removed deprecated Kconfig PRINTK64 symbol 2021-06-11 16:35:19 -05:00
Kconfig.cbprintf
assert.c
base64.c
bitarray.c sys: introduce bit arrays 2021-05-07 13:36:22 -04:00
cbprintf.c
cbprintf_complete.c lib: add default labels and comments to switch statements 2021-06-04 16:22:23 -05:00
cbprintf_nano.c coding guidelines 10.4: casting operands to have same types 2021-05-08 12:32:15 +02:00
cbprintf_packaged.c coding guidelines 11.9: fix literal zero as the null-ptr-constant 2021-05-12 21:51:40 -04:00
crc7_sw.c
crc8_sw.c
crc16_sw.c
crc32_sw.c
crc32c_sw.c
dec.c
fdtable.c fdtable: remove remains of switch 2021-06-05 10:38:04 -04:00
heap-validate.c lib: os: heap-validate: Fix wrong chunkid returned by max_chunkid() 2021-06-23 06:18:44 -04:00
heap.c k_heap: Clamp to a minimum heap size 2021-05-20 17:52:21 -04:00
heap.h heap: create unique variable name 2021-05-25 19:06:06 -04:00
hex.c
json.c
mpsc_pbuf.c lib: remove redundant check for null 2021-05-26 08:29:20 -05:00
mutex.c
notify.c
onoff.c
p4wq.c lib: os: add braces to 'if' statements 2021-06-04 16:20:44 -05:00
printk.c
rb.c
reboot.c
ring_buffer.c
sem.c
thread_entry.c
timeutil.c
user_work.c