This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] Fix undefined behaviour inconsistent for strtok
- From: Andreas Schwab <schwab at suse dot de>
- To: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- Cc: libc-alpha at sourceware dot org
- Date: Tue, 25 Oct 2016 13:31:25 +0200
- Subject: Re: [PATCH] Fix undefined behaviour inconsistent for strtok
- Authentication-results: sourceware.org; auth=none
- References: <1477393113-3845-1-git-send-email-adhemerval.zanella@linaro.org>
On Okt 25 2016, Adhemerval Zanella <adhemerval.zanella@linaro.org> wrote:
> * string/strtok.c (strtok): Return null is previous input is also
s/is/if/
> diff --git a/string/strtok.c b/string/strtok.c
> index 7a4574d..5c4b309 100644
> --- a/string/strtok.c
> +++ b/string/strtok.c
> @@ -40,8 +40,8 @@ STRTOK (char *s, const char *delim)
> {
> char *token;
>
> - if (s == NULL)
> - s = olds;
> + if ((s == NULL) && ((s = olds) == NULL))
Please avoid assignment in an expression. And the parens are redundant.
Andreas.
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."