Changeset dd50aa19 in mainline for kernel


Ignore:
Timestamp:
2024-09-12T12:35:23Z (10 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
899bdfd
Parents:
2ee6351
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-09-11 13:51:11)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-09-12 12:35:23)
Message:

Allocation function tweaks

  • Add reallocarray() from POSIX 2024 for overflow-safe reallocations.
  • Make realloc(x, 0) act as realloc(x, 1), and print an error message because it's unspecified behavior. Previous handling of realloc(x, 0) as free(x) is problematic, because proper realloc use will mistake it for failure if the case isn't specifically checked for, leading to double-free.
  • Make malloc(0) act as malloc(1), since it "just works" when code forgets to specifically check for zero in cases where zero length is meaningful.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/mm/malloc.c

    r2ee6351 rdd50aa19  
    211211void *realloc(void *old_obj, size_t new_size)
    212212{
     213        if (new_size == 0)
     214                new_size = 1;
     215
    213216        if (!old_obj)
    214217                return malloc(new_size);
Note: See TracChangeset for help on using the changeset viewer.