zsh-workers
 help / Atom feed
* [PATCH] parse: fix signed overflow in ecstrcode()
@ 2019-03-14  9:40 Kamil Dudka
  0 siblings, 0 replies; 1+ messages in thread
From: Kamil Dudka @ 2019-03-14  9:40 UTC (permalink / raw)
  To: zsh-workers

Detected by GCC with -fsanitize=undefined:

parse.c:420:47: runtime error: signed integer overflow: -2003020233 - 1064446834 cannot be represented in type 'int'
---
 Src/parse.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Src/parse.c b/Src/parse.c
index 83383f10c..22e553a16 100644
--- a/Src/parse.c
+++ b/Src/parse.c
@@ -414,10 +414,10 @@ ecstrcode(char *s)
 	return c;
     } else {
 	Eccstr p, *pp;
-	int cmp;
+	long cmp;
 
 	for (pp = &ecstrs; (p = *pp); ) {
-	    if (!(cmp = p->nfunc - ecnfunc) && !(cmp = (((signed)p->hashval) - ((signed)val))) && !(cmp = strcmp(p->str, s))) {
+	    if (!(cmp = p->nfunc - ecnfunc) && !(cmp = (((long)p->hashval) - ((long)val))) && !(cmp = strcmp(p->str, s))) {
 		return p->offs;
             }
 	    pp = (cmp < 0 ? &(p->left) : &(p->right));
-- 
2.17.2


^ permalink raw reply	[flat|nested] 1+ messages in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-14  9:40 [PATCH] parse: fix signed overflow in ecstrcode() Kamil Dudka

zsh-workers

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


AGPL code for this site: git clone https://public-inbox.org/ public-inbox