git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 18:09 UTC

[PATCH] [PATCH v2] gpg-interface.c: trim CR only before LF

From
OAOkhuomon Ajayi <okhuomonajayi54@gmail.com>
Date
Oct 16, 2025, 20:03 UTC
Message-ID
<20251016200344.43239-1-okhuomonajayi54@gmail.com>
Problem:
The function remove_cr_after() stripped CRs blindly. The comment suggested
NEEDSWORK: trim only CRs before LF. This caused potential confusion.

Solution: Rename remove_cr_after() to trim_cr_before_lf() and update the comment: "Trim CR characters only when they appear before LF (\r\n) line endings." This keeps lone CRs intact and documents intent clearly.

Also improved formatting.
Signed-off-by: Okhuomon Ajayi <okhuomonajayi54@gmail.com>
---
 gpg-interface.c | 34 ++++++++++++++++++++++++----------
 1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/gpg-interface.c b/gpg-interface.c
index c961607444..2d114e05e8 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -964,23 +964,37 @@ int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *sig
 	return use_format->sign_buffer(buffer, signature, signing_key);
 }
 
-/*
- * Trim CR characters only when they appear before LF (\r\n) line endings.
- * This avoids removing legitimate lone CRs from teh content.
- */
+/* Convert CRLF to LF, in case we are on Windows */
 static void trim_cr_before_lf(struct strbuf *buffer, size_t offset)
 {
 	size_t i, j;
 
+	for (i = j = offset; i < buffer->len; i++) {
+		/* Skip CR only if it comes right before LF */
+		if (buffer->buf[i] == '\r' && i + 1 < buffer->len &&
+		    buffer->buf[i + 1] == '\n')
+			continue;
+
+		if (i != j)
+			buffer->buf[j] = buffer->buf[i];
+		j++;
+	}
+	strbuf_setlen(buffer, j);
+}
+
+static void trim_cr_before_lf(struct strbuf *buffer, size_t offset)
+{
+        size_t i, j;
+
 	for (i = j = offset; i < buffer->len; i++) {
 	     /* skip CR only if it comes right before LF */
-		if (buffer->buf[i] == '\r' && i + 1 < buffer->len && buffer->buf[i+1] == '\n')
-		    continue;
+	     if (buffer->buf[i] == '\r' && i + 1 < buffer->len &&
+		 buffer->buf[i+1] == '\n')
+		     continue;
  
-			if (i != j)
-				buffer->buf[j] = buffer->buf[i];
-			j++;
-		
+             if (i != j)
+		     buffer->buf[j] = buffer->buf[i];
+	     j++;
 	}
 	strbuf_setlen(buffer, j);
 }
-- 
2.43.0
Next: Christian Couder
Message 1 of 3 in “gpg-interface.c: trim CR only before LF”
  1. [PATCH v2] gpg-interface.c: trim CR only before LFOkhuomon Ajayi, Oct 16, 2025
  2. Christian CouderOct 17, 2025
  3. Junio C HamanoOct 17, 2025

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.