summaryrefslogtreecommitdiff
path: root/base85.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2010-01-10 00:48:47 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2010-01-10 00:48:47 -0800
commit96aa7adda3b0254e4b9904f53bb38cd76bfea7bb (patch)
treed1eb57fbedb2e8c321889794c60ded86a9a2e88b /base85.c
parenttextconv: stop leaking file descriptors (diff)
parentbase85: Make the code more obvious instead of explaining the non-obvious (diff)
downloadtgif-96aa7adda3b0254e4b9904f53bb38cd76bfea7bb.tar.xz
Merge branch 'maint-1.6.0' into maint-1.6.1
* maint-1.6.0: base85: Make the code more obvious instead of explaining the non-obvious base85: encode_85() does not use the decode table base85 debug code: Fix length byte calculation checkout -m: do not try to fall back to --merge from an unborn branch branch: die explicitly why when calling "git branch [-a|-r] branchname".
Diffstat (limited to 'base85.c')
-rw-r--r--base85.c14
1 files changed, 3 insertions, 11 deletions
diff --git a/base85.c b/base85.c
index b88270f908..24ddf60eb0 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;
@@ -84,8 +78,6 @@ int decode_85(char *dst, const char *buffer, int len)
void encode_85(char *buf, const unsigned char *data, int bytes)
{
- prep_base85();
-
say("encode 85");
while (bytes) {
unsigned acc = 0;
@@ -118,7 +110,7 @@ int main(int ac, char **av)
int len = strlen(av[2]);
encode_85(buf, av[2], len);
if (len <= 26) len = len + 'A' - 1;
- else len = len + 'a' - 26 + 1;
+ else len = len + 'a' - 26 - 1;
printf("encoded: %c%s\n", len, buf);
return 0;
}