mailing list of musl libc
 help / color / Atom feed
* [musl] [PATCH] remove redundant condition in memccpy
@ 2020-03-09 18:32 Alexander Monakov
  2020-03-20 19:46 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Alexander Monakov @ 2020-03-09 18:32 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 426 bytes --]


Commit d9bdfd164 ("fix memccpy to not access buffer past given size")
correctly added a check for 'n' nonzero, but made the pre-existing test
'*s==c' redundant: n!=0 implies *s==c. Remove the unnecessary check.

Reported by Alexey Izbyshev.
---

Let me also point out that the aforementioned change did not appear
on this mailing list.

Alexander

 src/string/memccpy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


[-- Warning: decoded text below may be mangled --]
[-- Attachment #2: 0321-remove-redundant-condition-in-memccpy.patch --]
[-- Type: text/x-patch; name="0321-remove-redundant-condition-in-memccpy.patch", Size: 362 bytes --]

diff --git a/src/string/memccpy.c b/src/string/memccpy.c
index 00c18e2b..3b0a3700 100644
--- a/src/string/memccpy.c
+++ b/src/string/memccpy.c
@@ -29,6 +29,6 @@ void *memccpy(void *restrict dest, const void *restrict src, int c, size_t n)
 #endif
 	for (; n && (*d=*s)!=c; n--, s++, d++);
 tail:
-	if (n && *s==c) return d+1;
+	if (n) return d+1;
 	return 0;
 }

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

* Re: [musl] [PATCH] remove redundant condition in memccpy
  2020-03-09 18:32 [musl] [PATCH] remove redundant condition in memccpy Alexander Monakov
@ 2020-03-20 19:46 ` Rich Felker
  0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2020-03-20 19:46 UTC (permalink / raw)
  To: musl

On Mon, Mar 09, 2020 at 09:32:16PM +0300, Alexander Monakov wrote:
> 
> Commit d9bdfd164 ("fix memccpy to not access buffer past given size")
> correctly added a check for 'n' nonzero, but made the pre-existing test
> '*s==c' redundant: n!=0 implies *s==c. Remove the unnecessary check.
> 
> Reported by Alexey Izbyshev.
> ---
> 
> Let me also point out that the aforementioned change did not appear
> on this mailing list.
> 
> Alexander
> 
>  src/string/memccpy.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 

> diff --git a/src/string/memccpy.c b/src/string/memccpy.c
> index 00c18e2b..3b0a3700 100644
> --- a/src/string/memccpy.c
> +++ b/src/string/memccpy.c
> @@ -29,6 +29,6 @@ void *memccpy(void *restrict dest, const void *restrict src, int c, size_t n)
>  #endif
>  	for (; n && (*d=*s)!=c; n--, s++, d++);
>  tail:
> -	if (n && *s==c) return d+1;
> +	if (n) return d+1;
>  	return 0;
>  }


Thanks, applying.

Rich

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-09 18:32 [musl] [PATCH] remove redundant condition in memccpy Alexander Monakov
2020-03-20 19:46 ` Rich Felker

mailing list of musl libc

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

Example config snippet for mirrors

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


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