gbranden pushed a commit to branch master
in repository groff.
commit 195a6286601e34ff4eeceeb2daba076c0ba051c1
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sun Mar 15 14:27:43 2026 -0500
Trivially refactor (2/2).
Compare C/C++ objects of `char` type to character literals instead of
punning them down to Booleans.
* src/devices/xditview/device.c (find_file):
* src/libs/libgroff/device.cpp (device_init):
* src/libs/libgroff/searchpath.cpp (search_path::search_path):
* src/roff/groff/groff.cpp (main):
* src/roff/troff/input.cpp (interpolate_environment_variable): Do it.
---
ChangeLog | 12 ++++++++++++
src/devices/xditview/device.c | 3 ++-
src/libs/libgroff/device.cpp | 2 +-
src/libs/libgroff/searchpath.cpp | 4 ++--
src/roff/groff/groff.cpp | 8 ++++----
src/roff/troff/input.cpp | 2 +-
6 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 83102e471..3f4efc63f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2026-03-15 G. Branden Robinson <[email protected]>
+
+ Trivially refactor. Compare C/C++ objects of `char` type to
+ character literals instead of punning them down to Booleans.
+
+ * src/devices/xditview/device.c (find_file):
+ * src/libs/libgroff/device.cpp (device_init):
+ * src/libs/libgroff/searchpath.cpp (search_path::search_path):
+ * src/roff/groff/groff.cpp (main):
+ * src/roff/troff/input.cpp (interpolate_environment_variable):
+ Do it.
+
2026-03-15 G. Branden Robinson <[email protected]>
Trivially refactor. Compare return value of getenv(3) to
diff --git a/src/devices/xditview/device.c b/src/devices/xditview/device.c
index 131137dc2..16b44e21c 100644
--- a/src/devices/xditview/device.c
+++ b/src/devices/xditview/device.c
@@ -477,7 +477,8 @@ FILE *find_file(const char *file, char **result)
char *env;
env = getenv(FONT_ENV_VAR);
- path = XtMalloc((((env != NULL) && *env) ? strlen(env) + 1 : 0)
+ path = XtMalloc((((env != NULL) && (*env != '\0'))
+ ? strlen(env) + 1 : 0)
+ strlen(FONTPATH) + 1);
*path = '\0';
if (env && *env) {
diff --git a/src/libs/libgroff/device.cpp b/src/libs/libgroff/device.cpp
index 5d906ece7..29cdc5f0a 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 != 0 /* nullptr */) && tem[0])
+ if ((tem != 0 /* nullptr */) && (tem[0] != '\0'))
device = tem;
}
diff --git a/src/libs/libgroff/searchpath.cpp b/src/libs/libgroff/searchpath.cpp
index 6d4cb64f1..8c84aa93b 100644
--- a/src/libs/libgroff/searchpath.cpp
+++ b/src/libs/libgroff/searchpath.cpp
@@ -62,12 +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 != 0 /* nullptr */) && *home)
+ + (((home != 0 /* nullptr */) && (*home != '\0'))
? strlen(home) + 1 : 0)
+ ((standard && *standard) ? strlen(standard) : 0)
+ 1];
*dirs = '\0';
- if ((e != 0 /* nullptr */) && *e) {
+ if ((e != 0 /* nullptr */) && (*e != '\0')) {
strcat(dirs, e);
strcat(dirs, PATH_SEP);
}
diff --git a/src/roff/groff/groff.cpp b/src/roff/groff/groff.cpp
index bf11b0b14..96fe7b7cb 100644
--- a/src/roff/groff/groff.cpp
+++ b/src/roff/groff/groff.cpp
@@ -524,7 +524,7 @@ int main(int argc, char **argv)
e += '=';
e += Fargs;
char *fontpath = getenv("GROFF_FONT_PATH");
- if ((fontpath != 0 /* nullptr */) && *fontpath) {
+ if ((fontpath != 0 /* nullptr */) && (*fontpath != '\0')) {
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 != 0 /* nullptr */ && *path))
+ if ((path != 0 /* nullptr */ && (*path != '\0')))
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 != 0 /* nullptr */ && *binpath))
+ if ((binpath != 0 /* nullptr */ && (*binpath != '\0')))
f += binpath;
else {
binpath = relocatep(BINPATH);
f += binpath;
}
- if ((path != 0 /* nullptr */ && *path)) {
+ if ((path != 0 /* nullptr */ && (*path != '\0'))) {
f += PATH_SEP_CHAR;
f += path;
}
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 1ceda48a1..9177868e5 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -6008,7 +6008,7 @@ void unformat_macro()
static void interpolate_environment_variable(symbol nm)
{
const char *s = getenv(nm.contents());
- if ((s != 0 /* nullptr */) && (*s != 0 /* nullptr */))
+ if ((s != 0 /* nullptr */) && (*s != '\0'))
input_stack::push(make_temp_iterator(s));
}
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit