Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Avoid strlen calls after sprintf
- X-seq: zsh-workers 53334
- From: Oliver Kiddle <opk@xxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Cc: Zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: Avoid strlen calls after sprintf
- Date: Tue, 28 Jan 2025 13:01:10 +0100
- Archived-at: <https://zsh.org/workers/53334>
- In-reply-to: <CAH+w=7baXHAE+yfNGSJUndJBFpLv02cv3oh4TzULdo2KdpStKw@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <55461-1738028157.576993@J2TS.vueI.SU7s> <CAH+w=7baXHAE+yfNGSJUndJBFpLv02cv3oh4TzULdo2KdpStKw@mail.gmail.com>
Bart Schaefer wrote:
> In several of these cases it would also be possible to change
> dupstring() to dupstring_wlen(), because now the length is known
> before dup-ing.
Good point. I can only spot the one place.
Oliver
diff --git a/Src/Zle/compresult.c b/Src/Zle/compresult.c
index 61325ddd2..f8fe46914 100644
--- a/Src/Zle/compresult.c
+++ b/Src/Zle/compresult.c
@@ -489,7 +489,7 @@ static char *
build_pos_string(LinkList list)
{
LinkNode node;
- int l;
+ int l, buflen;
char buf[40], *s;
long p;
@@ -502,8 +502,9 @@ build_pos_string(LinkList list)
l += 1 + sprintf(buf, ":%ld", -p);
else
#endif
- l += 1 + sprintf(buf, "%ld", p);
- setdata(node, dupstring(buf));
+ buflen = sprintf(buf, "%ld", p);
+ setdata(node, dupstring_wlen(buf, buflen));
+ l += 1 + buflen;
}
s = (char *) zalloc(l * sizeof(char));
*s = 0;
Messages sorted by:
Reverse Date,
Date,
Thread,
Author