Changeset dd50aa19 in mainline for common/include/stdlib.h


Ignore:
Timestamp:
2024-09-12T12:35:23Z (8 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
  • common/include/stdlib.h

    r2ee6351 rdd50aa19  
    122122    __attribute__((malloc));
    123123
     124extern void *reallocarray(void *ptr, size_t nelem, size_t elsize)
     125    __attribute__((warn_unused_result));
     126
    124127__HELENOS_DECLS_END;
    125128#endif
Note: See TracChangeset for help on using the changeset viewer.