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

[PATCH 2/2] strbuf: make it clear that suffixcmp() should not be used for sorting

From
Christian Couder <chriscool@tuxfamily.org>
Date
Nov 4, 2013, 20:42 UTC
Message-ID
<20131104204251.16987.42654.chriscool@tuxfamily.org>

Nobody sane uses suffixcmp() for anything but checking with zero, but it is not very clear from the implementation that it should not be used for any sorting.

So let's make it clear that the callers should not expect anything but "does str have sfx as its suffix, yes or no?".

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 strbuf.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/strbuf.c b/strbuf.c
index 1170d01..9ba50de 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -16,7 +16,7 @@ int suffixcmp(const char *str, const char *suffix)
 	if (len < suflen)
 		return -1;
 	else
-		return strcmp(str + len - suflen, suffix);
+		return !!strcmp(str + len - suflen, suffix);
 }
 
 /*
-- 
1.8.4.1.576.g36ba827.dirty
Message 1 of 1 in “strbuf: make it clear that suffixcmp() should not be used for sorting”
  1. 2/2 strbuf: make it clear that suffixcmp() should not be used for sortingChristian Couder, Nov 4, 2013

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.