Re: [PATCH v7 1/7] strbuf: remove unnecessary NUL assignment in xstrdup_tolower()
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Feb 16, 2018, 12:55 UTC
- Message-ID
- <CACBZZX7mh6TpbaKUYQkCgL0j0waO4=RhR55GuawrzLSBnqDmXA@mail.gmail.com>
- In-Reply-To
- <20180215152711.158-2-lars.schneider@autodesk.com>
On Thu, Feb 15, 2018 at 4:27 PM, <lars.schneider@autodesk.com> wrote:
Show 11 quoted lines
> Since 3733e69464 (use xmallocz to avoid size arithmetic, 2016-02-22) we > allocate the buffer for the lower case string with xmallocz(). This > already ensures a NUL at the end of the allocated buffer. > > Remove the unnecessary assignment. > [...] > for (i = 0; i < len; i++) > result[i] = tolower(string[i]); > - result[i] = '\0'; > return result; > }
I agree with this approach, but it's worth noting for other reviewers that there's been some disagreement here on-list (between Eric & I) about whether these sorts of patterns should be removed or kept (although the calloc() case is slightly different from mallocz()), see: https://public-inbox.org/git/871shum182.fsf@evledraar.gmail.com/