Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: remove UncheckedMalloc(0) workaround #44543

Merged

Commits on Sep 8, 2022

  1. src: remove UncheckedMalloc(0) workaround

    Assuming that UncheckedMalloc(0) returns a non-nullptr is non-standard
    and we use other allocators as well (e.g., OPENSSL_malloc) that do not
    guarantee this behavior. It is the caller's responsibility to check that
    size != 0 implies UncheckedMalloc(size) != nullptr, and that's exactly
    what the checked variants (Malloc etc.) already do.
    
    The current behavior is also inconsistent with UncheckedRealloc(), which
    always returns a nullptr when the size is 0, and with the documentation
    in src/README.md as well as with multiple comments in the source code.
    
    This changes UncheckedMalloc(), UncheckedCalloc(), and
    UncheckedRealloc() to always return a nullptr when the size is 0 instead
    of doing fake allocations in UncheckedMalloc() and UncheckedCalloc()
    while returning a nullptr from UncheckedRealloc(). This is consistent
    with existing documentation and comments.
    
    Refs: nodejs#8571
    Refs: nodejs#8572
    tniessen committed Sep 8, 2022
    Copy the full SHA
    8dae03b View commit details
    Browse the repository at this point in the history