zsh-workers
 help / color / mirror / code / Atom feed
From: Wesley Schwengle <wesleys@opperschaap.net>
To: zsh-workers@zsh.org
Subject: [PATCH] Silence use-after-free warning in compmatch.c
Date: Tue,  4 Oct 2022 13:53:34 -0400	[thread overview]
Message-ID: <20221004175333.1250799-2-wesleys@opperschaap.net> (raw)
In-Reply-To: <20221004175333.1250799-1-wesleys@opperschaap.net>

compmatch.c:2081:26: warning: pointer ‘or’ used after ‘realloc’ [-Wuse-after-free]

Signed-off-by: Wesley Schwengle <wesleys@opperschaap.net>
---
 Src/Zle/compmatch.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/Src/Zle/compmatch.c b/Src/Zle/compmatch.c
index 56e5509a4..ddcecd589 100644
--- a/Src/Zle/compmatch.c
+++ b/Src/Zle/compmatch.c
@@ -2045,12 +2045,12 @@ join_strs(int la, char *sa, int lb, char *sb)
 				zlelineasstring(line, mp->llen, 0, &convlen,
 						NULL, 0);
 			    if (rr <= convlen) {
-				char *or = rs;
+				ptrdiff_t diff = rp - rs;
 				int alloclen = (convlen > 20) ? convlen : 20;
 
 				rs = realloc(rs, (rl += alloclen));
 				rr += alloclen;
-				rp += rs - or;
+				rp = rs + diff;
 			    }
 			    memcpy(rp, convstr, convlen);
 			    rp += convlen;
@@ -2073,11 +2073,11 @@ join_strs(int la, char *sa, int lb, char *sb)
 	} else {
 	    /* Same character, just take it. */
 	    if (rr <= 1 /* HERE charlen */) {
-		char *or = rs;
+		ptrdiff_t diff = rp - rs;
 
 		rs = realloc(rs, (rl += 20));
 		rr += 20;
-		rp += rs - or;
+		rp = rs + diff;
 	    }
 	    /* HERE: multibyte char */
 	    *rp++ = *sa;
-- 
2.38.0



  reply	other threads:[~2022-10-04 17:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-04 17:53 Fix use after free " Wesley Schwengle
2022-10-04 17:53 ` Wesley Schwengle [this message]
2022-10-17  4:18   ` [PATCH] Silence use-after-free " Jun T

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=20221004175333.1250799-2-wesleys@opperschaap.net \
    --to=wesleys@opperschaap.net \
    --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).