Skip to content

Use NULL instead of 0 as null pointer constant #1619

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

Merged
merged 1 commit into from
May 28, 2025

Conversation

ac000
Copy link
Member

@ac000 ac000 commented May 21, 2025

Use NULL instead of 0 as null pointer constant

GCC 15 enabled "-Wzero-as-null-pointer-constant" for C, which checks for
places where '0' has been used as a null pointer constant.

This showed a few places in Unit where we were using '0' instead of the
more correct NULL macro. E.g.

  $ make -j4 EXTRA_CFLAGS=-Wzero-as-null-pointer-constant
  ...
  src/nxt_buf.c: In function ‘nxt_buf_mmap_alloc’:
  src/nxt_buf.h:192:21: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant]
    192 |         (bm)->start = 0;                                                      \
        |                     ^
  src/nxt_buf.c:135:9: note: in expansion of macro ‘nxt_buf_mem_set_size’
    135 |         nxt_buf_mem_set_size(&b->mem, size);
        |         ^~~~~~~~~~~~~~~~~~~~

Signed-off-by: Andrew Clayton <[email protected]>

@ac000 ac000 changed the title Use NULL instead of 0 Use NULL instead of 0 as null pointer constant May 22, 2025
@ac000 ac000 marked this pull request as ready for review May 27, 2025 02:49
@ac000
Copy link
Member Author

ac000 commented May 27, 2025

Ignore the failing the Clang-AST test, it needs #1620

@ac000 ac000 requested a review from hongzhidao May 27, 2025 02:51
Copy link
Contributor

@hongzhidao hongzhidao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

GCC 15 enabled "-Wzero-as-null-pointer-constant" for C, which checks for
places where '0' has been used as a null pointer constant.

This showed a few places in Unit where we were using '0' instead of the
more correct NULL macro. E.g.

  $ make -j4 EXTRA_CFLAGS=-Wzero-as-null-pointer-constant
  ...
  src/nxt_buf.c: In function ‘nxt_buf_mmap_alloc’:
  src/nxt_buf.h:192:21: error: zero as null pointer constant [-Werror=zero-as-null-pointer-constant]
    192 |         (bm)->start = 0;                                                      \
        |                     ^
  src/nxt_buf.c:135:9: note: in expansion of macro ‘nxt_buf_mem_set_size’
    135 |         nxt_buf_mem_set_size(&b->mem, size);
        |         ^~~~~~~~~~~~~~~~~~~~

Signed-off-by: Andrew Clayton <[email protected]>
@ac000
Copy link
Member Author

ac000 commented May 28, 2025

Rebased with master

$ git range-diff 15f3f5cd...39f91213
-:  -------- > 1:  4fcbe9ca ci: clang-ast: Update to openjdk-21-jdk
1:  15f3f5cd = 2:  39f91213 Use NULL instead of 0 as null pointer constant

@ac000 ac000 merged commit 39f9121 into nginx:master May 28, 2025
25 checks passed
@ac000 ac000 deleted the zero-to-null branch May 28, 2025 15:45
@ac000
Copy link
Member Author

ac000 commented May 28, 2025

Thanks Zhidao!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants