gbranden pushed a commit to branch master
in repository groff.
commit c10be40a3d2ab6223b2d06c60a3ca9fc452bfa47
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Mar 15 11:26:28 2026 -0500
Trivially refactor.
Compare return value of getenv(3) to explicit null pointer constants
appropriate for C or C++ instead punning that return value down to a
Boolean.
* src/devices/grops/psrm.cpp (resource_manager::output_prolog):
* src/devices/grotty/tty.cpp (main):
* src/devices/xditview/device.c (find_file):
* src/libs/libgroff/curtime.cpp (current_time):
* src/libs/libgroff/device.cpp (device_init):
* src/libs/libgroff/relocate.cpp (set_current_prefix):
* src/libs/libgroff/searchpath.cpp (search_path::search_path):
* src/preproc/html/pre-html.cpp (scanArguments):
* src/preproc/refer/refer.cpp (possibly_load_default_database):
* src/roff/groff/groff.cpp (main):
* src/utils/lkbib/lkbib.cpp (main): Do it.
Also annotate null pointer constants in C++ source files with `nullptr`
comment to ease any future transition to C++11, which defines it as a
keyword.
---
ChangeLog | 18 ++++++++++++++++++
src/devices/grops/psrm.cpp | 2 +-
src/devices/grotty/tty.cpp | 2 +-
src/devices/xditview/device.c | 2 +-
src/libs/libgroff/curtime.cpp | 2 +-
src/libs/libgroff/device.cpp | 2 +-
src/libs/libgroff/relocate.cpp | 2 +-
src/libs/libgroff/searchpath.cpp | 5 +++--
src/libs/libgroff/tmpfile.cpp | 8 ++++----
src/preproc/html/pre-html.cpp | 2 +-
src/preproc/refer/refer.cpp | 2 +-
src/roff/groff/groff.cpp | 12 ++++++------
src/utils/lkbib/lkbib.cpp | 2 +-
13 files changed, 40 insertions(+), 21 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b4169536f..83102e471 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2026-03-15 G. Branden Robinson <[email protected]>
+
+ Trivially refactor. Compare return value of getenv(3) to
+ explicit null pointer constants appropriate for C or C++ instead
+ punning that return value down to a Boolean.
+
+ * src/devices/grops/psrm.cpp (resource_manager::output_prolog):
+ * src/devices/grotty/tty.cpp (main):
+ * src/devices/xditview/device.c (find_file):
+ * src/libs/libgroff/curtime.cpp (current_time):
+ * src/libs/libgroff/device.cpp (device_init):
+ * src/libs/libgroff/relocate.cpp (set_current_prefix):
+ * src/libs/libgroff/searchpath.cpp (search_path::search_path):
+ * src/preproc/html/pre-html.cpp (scanArguments):
+ * src/preproc/refer/refer.cpp (possibly_load_default_database):
+ * src/roff/groff/groff.cpp (main):
+ * src/utils/lkbib/lkbib.cpp (main): Do it.
+
2026-03-15 G. Branden Robinson <[email protected]>
* src/devices/grops/psrm.cpp (resource_manager::output_prolog):
diff --git a/src/devices/grops/psrm.cpp b/src/devices/grops/psrm.cpp
index 4ab30b765..352f99298 100644
--- a/src/devices/grops/psrm.cpp
+++ b/src/devices/grops/psrm.cpp
@@ -290,7 +290,7 @@ void resource_manager::output_prolog(ps_output &out)
FILE *outfp = out.get_file();
out.end_line();
char *path;
- if (!getenv("GROPS_PROLOGUE")) {
+ if (getenv("GROPS_PROLOGUE") == 0 /* nullptr */) {
string e = "GROPS_PROLOGUE";
e += '=';
e += GROPS_PROLOGUE;
diff --git a/src/devices/grotty/tty.cpp b/src/devices/grotty/tty.cpp
index 5b1adafdb..1e3a66cd6 100644
--- a/src/devices/grotty/tty.cpp
+++ b/src/devices/grotty/tty.cpp
@@ -980,7 +980,7 @@ int main(int argc, char **argv)
{
program_name = argv[0];
static char stderr_buf[BUFSIZ];
- if (getenv("GROFF_NO_SGR"))
+ if (getenv("GROFF_NO_SGR") != 0 /* nullptr */)
use_overstriking_drawing_scheme = true;
setbuf(stderr, stderr_buf);
setlocale(LC_CTYPE, "");
diff --git a/src/devices/xditview/device.c b/src/devices/xditview/device.c
index cc099d898..131137dc2 100644
--- a/src/devices/xditview/device.c
+++ b/src/devices/xditview/device.c
@@ -477,7 +477,7 @@ FILE *find_file(const char *file, char **result)
char *env;
env = getenv(FONT_ENV_VAR);
- path = XtMalloc(((env && *env) ? strlen(env) + 1 : 0)
+ path = XtMalloc((((env != NULL) && *env) ? strlen(env) + 1 : 0)
+ strlen(FONTPATH) + 1);
*path = '\0';
if (env && *env) {
diff --git a/src/libs/libgroff/curtime.cpp b/src/libs/libgroff/curtime.cpp
index e06e2fdd1..9d40cb323 100644
--- a/src/libs/libgroff/curtime.cpp
+++ b/src/libs/libgroff/curtime.cpp
@@ -41,7 +41,7 @@ struct tm *current_time()
t;
char *source_date_epoch = getenv("SOURCE_DATE_EPOCH");
- if (source_date_epoch) {
+ if (source_date_epoch != 0 /* nullptr */) {
errno = 0;
char *endptr;
long epoch = strtol(source_date_epoch, &endptr, 10);
diff --git a/src/libs/libgroff/device.cpp b/src/libs/libgroff/device.cpp
index bc8e2af86..5d906ece7 100644
--- a/src/libs/libgroff/device.cpp
+++ b/src/libs/libgroff/device.cpp
@@ -34,7 +34,7 @@ struct device_init {
device_init::device_init()
{
char *tem = getenv("GROFF_TYPESETTER");
- if (tem && tem[0])
+ if ((tem != 0 /* nullptr */) && tem[0])
device = tem;
}
diff --git a/src/libs/libgroff/relocate.cpp b/src/libs/libgroff/relocate.cpp
index 49ac8bd53..8b0760125 100644
--- a/src/libs/libgroff/relocate.cpp
+++ b/src/libs/libgroff/relocate.cpp
@@ -180,7 +180,7 @@ void set_current_prefix()
# endif /* DEBUG */
if (!curr_prefix && !strchr(program_name, '.')) { // try with extensions
pathextstr = strsave(getenv("PATHEXT"));
- if (!pathextstr)
+ if (0 /* nullptr */ == pathextstr)
pathextstr = strsave(PATH_EXT);
curr_prefix = searchpathext(program_name, pathextstr, getenv("PATH"));
delete[] pathextstr;
diff --git a/src/libs/libgroff/searchpath.cpp b/src/libs/libgroff/searchpath.cpp
index 2d5e599d2..6d4cb64f1 100644
--- a/src/libs/libgroff/searchpath.cpp
+++ b/src/libs/libgroff/searchpath.cpp
@@ -62,11 +62,12 @@ search_path::search_path(const char *envvar, const char
*standard,
e = getenv(envvar);
dirs = new char[((e && *e) ? strlen(e) + 1 : 0)
+ (add_current ? 1 + 1 : 0)
- + ((home && *home) ? strlen(home) + 1 : 0)
+ + (((home != 0 /* nullptr */) && *home)
+ ? strlen(home) + 1 : 0)
+ ((standard && *standard) ? strlen(standard) : 0)
+ 1];
*dirs = '\0';
- if (e && *e) {
+ if ((e != 0 /* nullptr */) && *e) {
strcat(dirs, e);
strcat(dirs, PATH_SEP);
}
diff --git a/src/libs/libgroff/tmpfile.cpp b/src/libs/libgroff/tmpfile.cpp
index 3c9248db8..d9968333a 100644
--- a/src/libs/libgroff/tmpfile.cpp
+++ b/src/libs/libgroff/tmpfile.cpp
@@ -74,15 +74,15 @@ temp_init::temp_init()
const char *tem;
// using the first match for any of the environment specs in listed order.
if (
- (tem = getenv(GROFF_TMPDIR_ENVVAR)) == 0
- && (tem = getenv(TMPDIR_ENVVAR)) == 0
+ (tem = getenv(GROFF_TMPDIR_ENVVAR)) == 0 /* nullptr */
+ && (tem = getenv(TMPDIR_ENVVAR)) == 0 /* nullptr */
#if defined(__MSDOS__) || defined(_WIN32)
// If we didn't find a match for either of the above
// (which are preferred, regardless of the host operating system),
// and we are hosted on either MS-Windows or MS-DOS,
// then try the Microsoft conventions.
- && (tem = getenv(WIN32_TMPDIR_ENVVAR)) == 0
- && (tem = getenv(MSDOS_TMPDIR_ENVVAR)) == 0
+ && (tem = getenv(WIN32_TMPDIR_ENVVAR)) == 0 /* nullptr */
+ && (tem = getenv(MSDOS_TMPDIR_ENVVAR)) == 0 /* nullptr */
#endif
)
// If we didn't find an environment spec fall back to this default.
diff --git a/src/preproc/html/pre-html.cpp b/src/preproc/html/pre-html.cpp
index 7b58903d8..a8a50cfd8 100644
--- a/src/preproc/html/pre-html.cpp
+++ b/src/preproc/html/pre-html.cpp
@@ -1602,7 +1602,7 @@ static void usage(FILE *stream)
static int scanArguments(int argc, char **argv)
{
const char *cmdprefix = getenv("GROFF_COMMAND_PREFIX");
- if (!cmdprefix)
+ if (0 /* nullptr */ == cmdprefix)
cmdprefix = PROG_PREFIX;
size_t pfxlen = strlen(cmdprefix);
char *troff_name = new char[pfxlen + strlen("troff") + 1];
diff --git a/src/preproc/refer/refer.cpp b/src/preproc/refer/refer.cpp
index e696323c2..70d8da4c5 100644
--- a/src/preproc/refer/refer.cpp
+++ b/src/preproc/refer/refer.cpp
@@ -437,7 +437,7 @@ static void possibly_load_default_database()
{
if (search_default && !default_database_loaded) {
char *filename = getenv("REFER");
- if (filename)
+ if (filename != 0 /* nullptr */)
database_list.add_file(filename);
else
database_list.add_file(DEFAULT_INDEX, 1);
diff --git a/src/roff/groff/groff.cpp b/src/roff/groff/groff.cpp
index ff2f0825f..bf11b0b14 100644
--- a/src/roff/groff/groff.cpp
+++ b/src/roff/groff/groff.cpp
@@ -169,7 +169,7 @@ int main(int argc, char **argv)
int opt;
const char *command_prefix = getenv("GROFF_COMMAND_PREFIX");
const char *encoding = getenv("GROFF_ENCODING");
- if (!command_prefix)
+ if (0 /* nullptr */ == command_prefix)
command_prefix = PROG_PREFIX;
commands[TROFF_INDEX].set_name(command_prefix, "troff");
static const struct option long_options[] = {
@@ -399,7 +399,7 @@ int main(int argc, char **argv)
}
if (need_pic)
commands[PIC_INDEX].set_name(command_prefix, "pic");
- if (encoding) {
+ if (encoding != 0 /* nullptr */) {
commands[PRECONV_INDEX].set_name("preconv");
if (!Kflag && *encoding)
commands[PRECONV_INDEX].append_arg("-e", encoding);
@@ -524,7 +524,7 @@ int main(int argc, char **argv)
e += '=';
e += Fargs;
char *fontpath = getenv("GROFF_FONT_PATH");
- if (fontpath && *fontpath) {
+ if ((fontpath != 0 /* nullptr */) && *fontpath) {
e += PATH_SEP_CHAR;
e += fontpath;
}
@@ -538,7 +538,7 @@ int main(int argc, char **argv)
char *path = getenv("PATH");
string g = "GROFF_PATH__";
g += '=';
- if (path && *path)
+ if ((path != 0 /* nullptr */ && *path))
g += path;
g += '\0';
saved_path = xstrdup(g.contents());
@@ -546,13 +546,13 @@ int main(int argc, char **argv)
char *binpath = getenv("GROFF_BIN_PATH");
string f = "PATH";
f += '=';
- if (binpath && *binpath)
+ if ((binpath != 0 /* nullptr */ && *binpath))
f += binpath;
else {
binpath = relocatep(BINPATH);
f += binpath;
}
- if (path && *path) {
+ if ((path != 0 /* nullptr */ && *path)) {
f += PATH_SEP_CHAR;
f += path;
}
diff --git a/src/utils/lkbib/lkbib.cpp b/src/utils/lkbib/lkbib.cpp
index de25c0798..4f92f1ae5 100644
--- a/src/utils/lkbib/lkbib.cpp
+++ b/src/utils/lkbib/lkbib.cpp
@@ -130,7 +130,7 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
char *filename = getenv("REFER");
- if (filename)
+ if (filename != 0 /* nullptr */)
list.add_file(filename);
else if (search_default)
list.add_file(DEFAULT_INDEX, 1);
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit