]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
prlimit: make code more robust
authorKarel Zak <kzak@redhat.com>
Wed, 14 Apr 2021 14:15:34 +0000 (16:15 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 14 Apr 2021 14:19:01 +0000 (16:19 +0200)
The prlimit description are always defined as static strings, but it
seems better to make the code more readable and robust for static
analyzers and readers.

Fix also missing gettext() call for description help.

Fixes: https://github.com/karelzak/util-linux/issues/1277
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/prlimit.c

index 18601efd304b491dbd7958fbef2bbd7ac61a5bdf..1bdb2cb45a93647f833cbf1a229983a84ec9fc2d 100644 (file)
@@ -233,10 +233,12 @@ static void add_scols_line(struct libscols_table *table, struct prlimit *l)
 
                switch (get_column_id(i)) {
                case COL_RES:
-                       str = xstrdup(l->desc->name);
+                       if (l->desc->name)
+                               str = xstrdup(l->desc->name);
                        break;
                case COL_HELP:
-                       str = xstrdup(l->desc->help);
+                       if (l->desc->help)
+                               str = xstrdup(_(l->desc->help));
                        break;
                case COL_SOFT:
                        if (l->rlim.rlim_cur == RLIM_INFINITY)
@@ -251,7 +253,8 @@ static void add_scols_line(struct libscols_table *table, struct prlimit *l)
                                xasprintf(&str, "%llu", (unsigned long long) l->rlim.rlim_max);
                        break;
                case COL_UNITS:
-                       str = l->desc->unit ? xstrdup(_(l->desc->unit)) : NULL;
+                       if (l->desc->unit)
+                               str = xstrdup(_(l->desc->unit));
                        break;
                default:
                        break;