dthain / basekernel

A simple OS kernel for research, teaching, and fun.
GNU General Public License v2.0
804 stars 109 forks source link

kmalloc ksplit condition confusion #259

Closed MrSmiler closed 3 years ago

MrSmiler commented 4 years ago

If I'm not mistaken there is something wrong with this ksplit condition line and according to this line c->length >= length so the result of length - c->length always gonna be negative or equal to zero, so the condition must not be passed but it will due to the KUNIT which is #define KUNIT sizeof(struct kmalloc_chunk) the sizeof function returns a unsigned integer and due to that the negative value that comes from length - c->length will be converted to a unsigned integer and gonna always pass the condition except when the length == c->length. so is the ksplit condition line a mistake or something else ?

dthain commented 3 years ago

Quite right! Fixed in #269