git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 1/5] strbuf: add xstrdup_toupper()

From
Lars Schneider <larsxschneider@gmail.com>
Date
Dec 29, 2017, 16:55 UTC
Message-ID
<0D8114C4-BC45-43D3-AA33-8954AEC9EA10@gmail.com>
In-Reply-To
<20171229155642.GA23935@tor.lan>
Show 36 quoted lines
> On 29 Dec 2017, at 16:56, Torsten Bögershausen <tboegi@web.de> wrote:
> 
> On Fri, Dec 29, 2017 at 04:22:18PM +0100, lars.schneider@autodesk.com wrote:
>> From: Lars Schneider <larsxschneider@gmail.com>
>> 
>> Create a copy of an existing string and make all characters upper case.
>> Similar xstrdup_tolower().
>> 
>> This function is used in a subsequent commit.
>> 
>> Signed-off-by: Lars Schneider <larsxschneider@gmail.com>
>> ---
>> strbuf.c | 13 +++++++++++++
>> strbuf.h |  1 +
>> 2 files changed, 14 insertions(+)
>> 
>> diff --git a/strbuf.c b/strbuf.c
>> index 323c49ceb3..54276e96e7 100644
>> --- a/strbuf.c
>> +++ b/strbuf.c
>> @@ -760,6 +760,19 @@ char *xstrdup_tolower(const char *string)
>> 	return result;
>> }
>> 
>> +char *xstrdup_toupper(const char *string)
>> +{
>> +	char *result;
>> +	size_t len, i;
>> +
>> +	len = strlen(string);
>> +	result = xmallocz(len);
>> +	for (i = 0; i < len; i++)
>> +		result[i] = toupper(string[i]);
>> +	result[i] = '\0';
>        ^^^^^^^^^^^^^^^^
> 	Isn't this already done by xmallocz()
I copied that code from xstrdup_tolower().

The original implementation [1] and its refactored version [2] used xmalloc(). Later on xmallocz [3] was introduced.

[3] states "we can stop manually placing NUL at the end of the allocated buffer. But that's only safe if it's clear that the contents will always fill the buffer."

As far as I understand it, the content should always fill the buffer in the upper/lower case conversion. Therefore, I agree with you that the assignment is not necessary.

- Lars

[1] d4770964d5 (config: "git config --get-urlmatch" parses section.<url>.key, 2013-07-31) [2] 88d5a6f6cd (daemon/config: factor out duplicate xstrdup_tolower, 2014-05-22) [3] 3733e69464 (use xmallocz to avoid size arithmetic, 2016-02-22)

Previous: Torsten BögershausenNext: lars.schneider@autodesk.com
Message 4 of 26 in “convert: add support for different encodings”
  1. 0/5 convert: add support for different encodingslars.schneider@autodesk.com, Dec 29, 2017
  2. 1/5 strbuf: add xstrdup_toupper()lars.schneider@autodesk.com, Dec 29, 2017
  3. Torsten BögershausenDec 29, 2017
  4. Lars SchneiderDec 29, 2017
  5. 2/5 utf8: add function to detect prohibited UTF-16/32 BOMlars.schneider@autodesk.com, Dec 29, 2017
  6. 5/5 convert: add tracing for checkout-encodinglars.schneider@autodesk.com, Dec 29, 2017
  7. 4/5 convert: add support for 'checkout-encoding' attributelars.schneider@autodesk.com, Dec 29, 2017
  8. Torsten BögershausenDec 29, 2017
  9. Lars SchneiderDec 30, 2017
  10. 3/5 utf8: add function to detect a missing UTF-16/32 BOMlars.schneider@autodesk.com, Dec 29, 2017
  11. 0/5 V2B: simplify convert.c/htboegi@web.de, Dec 31, 2017
  12. 5/5 convert: add support for 'checkout-encoding' attributetboegi@web.de, Dec 31, 2017
  13. Johannes SchindelinJan 5, 2018
  14. 3/5 utf8: add function to detect prohibited UTF-16/32 BOMtboegi@web.de, Dec 31, 2017
  15. 1/5 convert_to_git(): checksafe becomes an integertboegi@web.de, Dec 31, 2017
  16. Lars SchneiderDec 31, 2017
  17. 1/1 convert_to_git(): checksafe becomes int conv_flagstboegi@web.de, Jan 1, 2018
  18. Lars SchneiderJan 2, 2018
  19. Torsten BögershausenJan 3, 2018
  20. Lars SchneiderJan 3, 2018
  21. Lars SchneiderJan 5, 2018
  22. Torsten BögershausenJan 5, 2018
  23. Junio C HamanoJan 5, 2018
  24. Lars SchneiderJan 6, 2018
  25. 2/5 strbuf: add xstrdup_toupper()tboegi@web.de, Dec 31, 2017
  26. 4/5 utf8: add function to detect a missing UTF-16/32 BOMtboegi@web.de, Dec 31, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.