Skip to content

Consistently represent null pointers with NULL - #1029

Open
JohnoKing wants to merge 3 commits into
ksh93:devfrom
JohnoKing:fix-null-pointer-warnings
Open

JohnoKing wants to merge 3 commits into
ksh93:devfrom
JohnoKing:fix-null-pointer-warnings

Conversation

@JohnoKing

Copy link
Copy Markdown

This relatively unimportant pull request implements the following changes:

  • Fixed 3,427+ -Wzero-as-null-pointer-constant warnings when compiling with Clang 22.1.8. This is primarily for code style consistency (previous usage of 0 and NULL was seemingly random).
    • Switched some struct initialization to C99 style incidentally to also fix some -Wzero-as-null-pointer-constant warnings. Progresses Migrate code to C99 #777
  • Fixed a few variable typing nits in the conf.tab tests; also removed some fallback test code for IRIX.

This relatively unimportant pull request implements
the following changes:

- Fixed 3,427+ -Wzero-as-null-pointer-constant warnings when compiling
  with Clang 22.1.8. This is primarily for code style consistency
  (previous usage of 0 and NULL was seemingly random).
  - Switched some struct init to C99 style incidentally to also
    fix some -Wzero-as-null-pointer-constant warnings.
    Progresses ksh93#777
- Fixed a few typing nits in conf.tab tests; also removed some fallback
  test code for IRIX.
@McDutchie

Copy link
Copy Markdown

Nice; thanks. At long last we're rid of the 0/NULL annoyance.

I'll need to verify that this builds on Solaris 11.4 with Solaris Studio cc; I seem to recall it doesn't like the use NULL (defined as ((void*)0)) for function pointers.

@McDutchie

McDutchie commented Sep 21, 2026

Copy link
Copy Markdown

Ah ha, I forgot I already took care of that three years ago (commit 0309d74) in features/standards, the results of which get included everywhere.

/*
* Though POSIX says it must be allowed, Solaris Studio cc dislikes NULL, a.k.a.
* (void*)0, being used for function pointers. It warns, or in some cases it even
* throws an error. Just use 0 for NULL, as that is always acceptable in C.
*/
#if __SUNPRO_C
#undef NULL
#define NULL 0
#endif /* __SUNPRO_C */

@McDutchie

Copy link
Copy Markdown

I'm getting a build error with this PR:

# src/cmd/ksh93/Mamfile: 1027-1030: make init.o
+ cc -D_BLD_ksh -O0 -g -funsigned-char -Wall -Wsign-compare -Wshorten-64-to-32 -Wsign-conversion -Wimplicit-int-conversion -fno-strict-aliasing '-DSH_DICT="libshell"' -I. -I/usr/local/src/ksh93/ksh/src/cmd/ksh93 -Iinclude -I/usr/local/src/ksh93/ksh/src/cmd/ksh93/include -I/usr/local/src/ksh93/ksh/arch/darwin.arm64-64,d/include/ast '-D_API_ast=20100309' -c /usr/local/src/ksh93/ksh/src/cmd/ksh93/sh/init.c
/usr/local/src/ksh93/ksh/src/cmd/ksh93/sh/init.c:2036:24: warning: pointer/integer type mismatch in conditional expression ('wctrans_t' (aka 'int') and 'void *') [-Wconditional-type-mismatch]
 2036 |         wctrans_t       trans = name?wctrans(name):NULL;
      |                                     ^~~~~~~~~~~~~~ ~~~~
/usr/local/src/ksh93/ksh/src/cmd/ksh93/sh/init.c:2036:12: error: incompatible pointer to integer conversion initializing 'wctrans_t' (aka 'int') with an expression of type 'void *' [-Wint-conversion]
 2036 |         wctrans_t       trans = name?wctrans(name):NULL;
      |                         ^       ~~~~~~~~~~~~~~~~~~~~~~~
1 warning and 1 error generated.

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