From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Kamil Dudka <kdudka@redhat.com>
Cc: zsh-workers@zsh.org
Subject: Re: PATCH: spelling correction buffer overflow
Date: Wed, 28 Mar 2018 16:07:24 +0200 [thread overview]
Message-ID: <11608.1522246044@thecus> (raw)
In-Reply-To: <2328442.7oMNVitVLA@kdudka-nb>
Kamil Dudka wrote:
> I spotted that this patch introduced new compiler warnings:
>
> Src/utils.c:4430:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
> # return (new - newname) >= (sizeof(newname)-1) ? NULL : newname;
-Wsign-compare is not on by default and turning it on results in quite a
few warnings for the zsh code. It seems a little silly given that the
compiler ought to be able evaluate sizeof() at compile time and
establish that it is within the range of a signed integer.
> Should we cast RHS of the >= operator to ssize_t or ptrdiff_t to avoid them?
Casts are a bit ugly. The following - adding newname to both the LHS
and RHS - appears to avoid the warning by making both sides of the
comparison of type signed. At least until someone decides that adding an
unsigned to the signed should also generate a warning.
Oliver
diff --git a/Src/utils.c b/Src/utils.c
index eab407eee..3587c3622 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -4396,7 +4396,7 @@ spname(char *oldname)
* Rationale for this, if there ever was any, has been forgotten. */
for (;;) {
while (*old == '/') {
- if ((new - newname) >= (sizeof(newname)-1))
+ if (new >= newname + sizeof(newname) - 1)
return NULL;
*new++ = *old++;
}
@@ -4427,7 +4427,7 @@ spname(char *oldname)
if (bestdist < maxthresh) {
struncpy(&new, spnameguess, sizeof(newname) - (new - newname));
struncpy(&new, old, sizeof(newname) - (new - newname));
- return (new - newname) >= (sizeof(newname)-1) ? NULL : newname;
+ return (new >= newname + sizeof(newname) - 1) ? NULL : newname;
} else
return NULL;
} else {
@@ -4435,7 +4435,7 @@ spname(char *oldname)
bestdist += thisdist;
}
for (p = spnamebest; (*new = *p++);) {
- if ((new - newname) >= (sizeof(newname)-1))
+ if (new >= newname + sizeof(newname) - 1)
return NULL;
new++;
}
next prev parent reply other threads:[~2018-03-29 1:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-26 22:39 Oliver Kiddle
2018-03-27 21:55 ` Kamil Dudka
2018-03-27 23:10 ` Bart Schaefer
2018-03-28 8:01 ` Kamil Dudka
2018-03-28 11:20 ` Kamil Dudka
2018-03-28 14:07 ` Oliver Kiddle [this message]
2018-03-29 8:42 ` Kamil Dudka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11608.1522246044@thecus \
--to=okiddle@yahoo.co.uk \
--cc=kdudka@redhat.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).