commit: 6efeab34dba910ab3c1636e0ef427ca947992d31
parent f96bbd71f6d63d9bdb93a209408929165eeeebcd
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Tue, 11 Mar 2025 10:01:10 +0100
check setlocale() return value, emit warning if NULL
Diffstat:
10 files changed, 83 insertions(+), 11 deletions(-)
diff --git a/cmd/cut.c b/cmd/cut.c
@@ -366,7 +366,14 @@ main(int argc, char *argv[])
{
char *opt_list = NULL;
- setlocale(LC_ALL, "");
+ char *lc_all = setlocale(LC_ALL, "");
+ if(lc_all == NULL)
+ {
+ fprintf(stderr,
+ "%s: warning: Failed loading locales. setlocale(LC_ALL, \"\"): %s\n",
+ argv0,
+ strerror(errno));
+ }
errno = 0;
for(int c = -1; (c = getopt(argc, argv, ":b:c:d:f:ns")) != -1;)
diff --git a/cmd/date.c b/cmd/date.c
@@ -135,7 +135,14 @@ main(int argc, char *argv[])
bool jflag = false;
bool settime = false;
- setlocale(LC_ALL, "");
+ char *lc_all = setlocale(LC_ALL, "");
+ if(lc_all == NULL)
+ {
+ fprintf(stderr,
+ "%s: warning: Failed loading locales. setlocale(LC_ALL, \"\"): %s\n",
+ argv0,
+ strerror(errno));
+ }
errno = 0;
if(clock_gettime(CLOCK_REALTIME, &tp) != 0)
diff --git a/cmd/expr.y b/cmd/expr.y
@@ -285,7 +285,13 @@ main(int argc, char *argv[])
{
int c;
- setlocale(LC_ALL, "");
+ char *lc_all = setlocale(LC_ALL, "");
+ if(lc_all == NULL)
+ {
+ fprintf(stderr, "%s: warning: Failed loading locales. setlocale(LC_ALL, \"\"): %s\n", argv0, strerror(errno));
+ }
+ errno = 0;
+
if (getenv("EXPR_COMPAT") != NULL
|| getenv("POSIXLY_CORRECT") != NULL) {
av = argv + 1;
diff --git a/cmd/join.c b/cmd/join.c
@@ -37,11 +37,12 @@
#include "../lib/err.h"
+#include <errno.h>
#include <limits.h>
#include <locale.h>
#include <stdio.h> // fgetln
#include <stdlib.h>
-#include <string.h> // strsep
+#include <string.h> // strsep, strerror
#include <sys/param.h>
#include <unistd.h>
#include <wchar.h>
@@ -113,7 +114,14 @@ main(int argc, char *argv[])
int aflag, ch, cval, vflag;
char *end;
- setlocale(LC_ALL, "");
+ char *lc_all = setlocale(LC_ALL, "");
+ if(lc_all == NULL)
+ {
+ fprintf(stderr,
+ "%s: warning: Failed loading locales. setlocale(LC_ALL, \"\"): %s\n",
+ argv0,
+ strerror(errno));
+ }
F1 = &input1;
F2 = &input2;
diff --git a/cmd/mv.c b/cmd/mv.c
@@ -442,7 +442,14 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
- setlocale(LC_ALL, "");
+ char *lc_all = setlocale(LC_ALL, "");
+ if(lc_all == NULL)
+ {
+ fprintf(stderr,
+ "%s: warning: Failed loading locales. setlocale(LC_ALL, \"\"): %s\n",
+ argv0,
+ strerror(errno));
+ }
errno = 0;
consent_init();
diff --git a/cmd/paste.c b/cmd/paste.c
@@ -211,7 +211,14 @@ usage(void)
int
main(int argc, char *argv[])
{
- setlocale(LC_ALL, "");
+ char *lc_all = setlocale(LC_ALL, "");
+ if(lc_all == NULL)
+ {
+ fprintf(stderr,
+ "%s: warning: Failed loading locales. setlocale(LC_ALL, \"\"): %s\n",
+ argv0,
+ strerror(errno));
+ }
errno = 0;
int seq = 0;
diff --git a/cmd/printf.c b/cmd/printf.c
@@ -96,7 +96,14 @@ main(int argc, char *argv[])
int end, rval;
char *format, *fmt, *start;
- (void)setlocale(LC_ALL, "");
+ char *lc_all = setlocale(LC_ALL, "");
+ if(lc_all == NULL)
+ {
+ fprintf(stderr,
+ "%s: warning: Failed loading locales. setlocale(LC_ALL, \"\"): %s\n",
+ argv0,
+ strerror(errno));
+ }
for(int c = -1; (c = getopt(argc, argv, "")) != -1;)
{
diff --git a/cmd/rm.c b/cmd/rm.c
@@ -207,7 +207,14 @@ main(int argc, char *argv[])
argc -= optind;
argv += optind;
- setlocale(LC_ALL, "");
+ char *lc_all = setlocale(LC_ALL, "");
+ if(lc_all == NULL)
+ {
+ fprintf(stderr,
+ "%s: warning: Failed loading locales. setlocale(LC_ALL, \"\"): %s\n",
+ argv0,
+ strerror(errno));
+ }
errno = 0;
consent_init();
diff --git a/cmd/test.c b/cmd/test.c
@@ -211,7 +211,16 @@ main(int argc, char **argv)
/* no expression => false */
if(--argc <= 0) return 1;
- (void)setlocale(LC_CTYPE, "");
+ char *lc_ctype = setlocale(LC_CTYPE, "");
+ if(lc_ctype == NULL)
+ {
+ fprintf(stderr,
+ "%s: warning: Failed loading locales. setlocale(LC_CTYPE, \"\"): %s\n",
+ argv0,
+ strerror(errno));
+ }
+ errno = 0;
+
nargc = argc;
t_wp = &argv[1];
parenlevel = 0;
diff --git a/cmd/wc.c b/cmd/wc.c
@@ -211,7 +211,14 @@ usage(void)
int
main(int argc, char *argv[])
{
- setlocale(LC_ALL, "");
+ char *lc_all = setlocale(LC_ALL, "");
+ if(lc_all == NULL)
+ {
+ fprintf(stderr,
+ "%s: warning: Failed loading locales. setlocale(LC_ALL, \"\"): %s\n",
+ argv0,
+ strerror(errno));
+ }
errno = 0;
int (*wc_file)(int, char *) = &wc_file_bytes;