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

[PATCH 3/3] base85: Make the code more obvious instead of explaining the non-obvious

From
AGAndreas Gruenbacher <agruen@suse.de>
Date
Jan 8, 2010, 13:40 UTC
Message-ID
<1262958000-27181-3-git-send-email-agruen@suse.de>
In-Reply-To
<alpine.LFD.2.00.1001071253400.21025@xanadu.home>
Here is another cleanup ...
Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
---
 base85.c |   10 ++--------
 1 files changed, 2 insertions(+), 8 deletions(-)
diff --git a/base85.c b/base85.c
index 7204ce2..e459fee 100644
--- a/base85.c
+++ b/base85.c
@@ -57,14 +57,8 @@ int decode_85(char *dst, const char *buffer, int len)
 		de = de85[ch];
 		if (--de < 0)
 			return error("invalid base85 alphabet %c", ch);
-		/*
-		 * Detect overflow.  The largest
-		 * 5-letter possible is "|NsC0" to
-		 * encode 0xffffffff, and "|NsC" gives
-		 * 0x03030303 at this point (i.e.
-		 * 0xffffffff = 0x03030303 * 85).
-		 */
-		if (0x03030303 < acc ||
+		/* Detect overflow. */
+		if (0xffffffff / 85 < acc ||
 		    0xffffffff - de < (acc *= 85))
 			return error("invalid base85 sequence %.5s", buffer-5);
 		acc += de;
-- 
1.6.6.75.g37bae
Previous: Andreas GruenbacherNext: A Large Angry SCM
Message 10 of 11 in “base85: Two tiny fixes”
  1. Andreas GruenbacherJan 7, 2010
  2. Nicolas PitreJan 7, 2010
  3. Andreas GruenbacherJan 8, 2010
  4. 1/3 base85 debug code: Fix length byte calculationAndreas Gruenbacher, Jan 8, 2010
  5. 2/3 base85: No need to initialize the decode table in encode_85Andreas Gruenbacher, Jan 8, 2010
  6. Michael J GruberJan 8, 2010
  7. Junio C HamanoJan 8, 2010
  8. base85: encode85() does not use the decode tableAndreas Gruenbacher, Jan 8, 2010
  9. base85: encode_85() does not use the decode tableAndreas Gruenbacher, Jan 8, 2010
  10. 3/3 base85: Make the code more obvious instead of explaining the non-obviousAndreas Gruenbacher, Jan 8, 2010
  11. A Large Angry SCMJan 8, 2010

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.