diff options
| author | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-25 00:30:44 -0600 |
|---|---|---|
| committer | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-25 00:30:44 -0600 |
| commit | 5f92e02ff71be19067a422d324beb610cacd084d (patch) | |
| tree | 1af510b0e4b9e3de95b18f476a6ebff2f109c488 /src/util.c | |
| parent | 7a7320b6a0d7dd6864b708b7e74fb5032a5bdf8e (diff) | |
| download | zash-chore/c23-nullptr-constexpr.tar.gz | |
C23: nullptr for null pointers, constexpr for typed constantschore/c23-nullptr-constexpr
nullptr in every place a null pointer constant was meant; NULL is gone
from src/.
constexpr where it improves on #define without costing anything: the
IGGCSI00 work-area offsets and sizes, and the scalar sizes MVS_DSN_MAX,
CSI_FIELD_LEN, CSI_WORK_MIN, PDS_DIRBLK, CSI_WORK, CSI_MAX_CALLS. A
constexpr in C is a constant expression, so it still bounds the arrays
that use it, and it now carries a type and can be checked with
static_assert. Feature switches (#if), the CSIETYPE/EBCDIC byte
constants read as octets, and the related-constant enum sets stay as
they were.
Diffstat (limited to 'src/util.c')
| -rw-r--r-- | src/util.c | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -31,7 +31,7 @@ } /** - * @brief Allocate memory. Never returns NULL. + * @brief Allocate memory. Never returns nullptr. * @param n Bytes wanted (0 is treated as 1). * @return The block. The shell exits if memory is exhausted. */ @@ -43,8 +43,8 @@ void *xmalloc(size_t n) { } /** - * @brief Resize a heap block. Never returns NULL. - * @param p Block from xmalloc(), or NULL. + * @brief Resize a heap block. Never returns nullptr. + * @param p Block from xmalloc(), or nullptr. * @param n New size in bytes. * @return The resized block. The shell exits if memory is exhausted. */ @@ -155,7 +155,7 @@ static void arena_add_chunk(arena *a, size_t need) { arena_chunk *c; if (need <= size && a->spare) { c = a->spare; - a->spare = NULL; + a->spare = nullptr; } else { if (size < need) size = need; @@ -196,7 +196,7 @@ void *arena_alloc(arena *a, size_t n) { * block is allocated and the old contents copied. * * @param a The arena. - * @param p Existing block, or NULL. + * @param p Existing block, or nullptr. * @param oldn Its size. * @param newn Size wanted. * @return The block, possibly moved. @@ -245,7 +245,7 @@ void arena_release(arena *a, arena_marker m) { arena_drop_chunk(a, c); } a->next = m.next; - a->end = a->head ? a->head->end : NULL; + a->end = a->head ? a->head->end : nullptr; } /** @@ -285,7 +285,7 @@ void arena_reset(arena *a) { void arena_unref(arena *a) { if (--a->refs > 0) return; - arena_release(a, (arena_marker){NULL, NULL}); + arena_release(a, (arena_marker){nullptr, nullptr}); free(a->spare); free(a); } @@ -311,12 +311,12 @@ void sb_reserve(strbuf *b, size_t extra) { /** * @brief Append bytes to a string builder. * @param b The builder. - * @param s Bytes to append. May be NULL when `n` is 0. + * @param s Bytes to append. May be nullptr when `n` is 0. * @param n How many. */ void sb_put(strbuf *b, const char *s, size_t n) { if (!n) - return; /* `s` may be null: memcpy(p, NULL, 0) is undefined */ + return; /* `s` may be null: memcpy(p, nullptr, 0) is undefined */ sb_reserve(b, n); memcpy(b->s + b->len, s, n); b->len += n; |
