Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[PATCH] silence gcc warnings
- X-seq: zsh-workers 53578
- From: dana <dana@xxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: [PATCH] silence gcc warnings
- Date: Sat, 10 May 2025 23:21:48 -0500
- Archived-at: <https://zsh.org/workers/53578>
- Feedback-id: i9be146f9:Fastmail
- List-id: <zsh-workers.zsh.org>
this fixes some warnings produced by gcc 14.2, all -Wformat-overflow and
-Wmaybe-uninitialized. the former were spurious because we checked the
length ahead of time, but i tried to make it happy. the other ones, i
didn't investigate closely enough to tell if they were actual issues
dana
diff --git a/Src/Zle/computil.c b/Src/Zle/computil.c
index 6ac458c91..280e1dbd8 100644
--- a/Src/Zle/computil.c
+++ b/Src/Zle/computil.c
@@ -1841,7 +1841,7 @@ ca_inactive(Cadef d, char **xor, int cur, int opts)
for (; (x = (opts ? "-" : *xor)); xor++) {
int excludeall = 0;
char *grp = NULL;
- size_t grplen;
+ size_t grplen = 0;
char *next, *sep = x;
while (*sep != '+' && *sep != '-' && *sep != ':' && *sep != '*' && !idigit(*sep)) {
diff --git a/Src/Zle/zle_refresh.c b/Src/Zle/zle_refresh.c
index f076bdd61..bb1c77757 100644
--- a/Src/Zle/zle_refresh.c
+++ b/Src/Zle/zle_refresh.c
@@ -1195,7 +1195,7 @@ zrefresh(void)
rpms.sen = *nbuf + winw;
for (t = tmpline, tmppos = 0; tmppos < tmpll; t++, tmppos++) {
zattr base_attr = mixattrs(default_attr, prompt_attr);
- zattr all_attr;
+ zattr all_attr = 0;
struct region_highlight *rhp;
int layer, nextlayer = 0;
/*
diff --git a/Src/builtin.c b/Src/builtin.c
index 5563bdba9..6fb3c47aa 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -3332,9 +3332,8 @@ add_autoload_function(Shfunc shf, char *funcname)
&& (shf2->node.flags & PM_LOADDIR) && (shf2->node.flags & PM_ABSPATH_USED)
&& shf2->filename)
{
- if (strlen(shf2->filename) + strlen(funcname) + 1 < PATH_MAX)
+ if (snprintf(buf, PATH_MAX, "%s/%s", shf2->filename, funcname) < PATH_MAX)
{
- sprintf(buf, "%s/%s", shf2->filename, funcname);
/* Set containing directory if the function file
* exists (do normal FPATH processing otherwise) */
if (!access(buf, R_OK)) {
diff --git a/Src/exec.c b/Src/exec.c
index c1181c5eb..b98b99558 100644
--- a/Src/exec.c
+++ b/Src/exec.c
@@ -2922,7 +2922,7 @@ execcmd_exec(Estate state, Execcmd_params eparams,
struct multio *mfds[10];
char *text;
int save[10];
- int fil, dfil, is_cursh, do_exec = 0, redir_err = 0, i;
+ int fil, dfil, is_cursh = 0, do_exec = 0, redir_err = 0, i;
int nullexec = 0, magic_assign = 0, forked = 0, old_lastval;
int is_shfunc = 0, is_builtin = 0, is_exec = 0, use_defpath = 0;
/* Various flags to the command. */
@@ -6254,12 +6254,14 @@ getfpfunc(char *s, int *ksh, char **fdir, char **alt_path, int test_only)
pp = alt_path ? alt_path : fpath;
for (; *pp; pp++) {
- if (strlen(*pp) + strlen(s) + 1 >= PATH_MAX)
+ if (**pp) {
+ if (snprintf(buf, PATH_MAX, "%s/%s", *pp, s) >= PATH_MAX)
+ continue;
+ } else if (strlen(s) >= PATH_MAX) {
continue;
- if (**pp)
- sprintf(buf, "%s/%s", *pp, s);
- else
+ } else {
strcpy(buf, s);
+ }
if ((r = try_dump_file(*pp, s, buf, ksh, test_only))) {
if (fdir)
*fdir = *pp;
@@ -6407,12 +6409,14 @@ cancd(char *s)
return NULL;
if (!nocdpath)
for (cp = cdpath; *cp; cp++) {
- if (strlen(*cp) + strlen(s) + 1 >= PATH_MAX)
+ if (**cp) {
+ if (snprintf(sbuf, PATH_MAX, "%s/%s", *cp, s) >= PATH_MAX)
+ continue;
+ } else if (strlen(s) >= PATH_MAX) {
continue;
- if (**cp)
- sprintf(sbuf, "%s/%s", *cp, s);
- else
+ } else {
strcpy(sbuf, s);
+ }
if (cancd2(sbuf)) {
doprintdir = -1;
return dupstring(sbuf);
Messages sorted by:
Reverse Date,
Date,
Thread,
Author