* Re: base85: Two tiny fixes
2010-01-07 17:58 ` Nicolas Pitre
@ 2010-01-08 13:02 ` Andreas Gruenbacher
2010-01-08 13:39 ` [PATCH 1/3] base85 debug code: Fix length byte calculation Andreas Gruenbacher
` (2 subsequent siblings)
3 siblings, 0 replies; 11+ messages in thread
From: Andreas Gruenbacher @ 2010-01-08 13:02 UTC (permalink / raw)
To: Nicolas Pitre; +Cc: git
On Thursday 07 January 2010 18:58:01 Nicolas Pitre wrote:
> ACK. Please post them to this list.
Okay, done.
> On Thu, 7 Jan 2010, Andreas Gruenbacher wrote:
> > There is another little oddity in the way the de85 table is set up: 0
> > indicates an invalid entry; to avoid this from clashing with a valid entry,
> > valid entries are incremented by one and decremented again while decoding.
> > This leads to slightly worse code than using a negative number to indicate
> > invalid values (and avoiding to increment/decrement).
>
> You can make a patch to modify that as well if you wish.
Nah, it's not worth the noise.
> And in that case don't forget to make de85 explicitly signed as a char is
> unsigned by default on some platforms.
I would have forgotten this; thanks for pointing it out!
Thanks,
Andreas
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 1/3] base85 debug code: Fix length byte calculation
2010-01-07 17:58 ` Nicolas Pitre
2010-01-08 13:02 ` Andreas Gruenbacher
@ 2010-01-08 13:39 ` Andreas Gruenbacher
2010-01-08 13:39 ` [PATCH 2/3] base85: No need to initialize the decode table in encode_85 Andreas Gruenbacher
2010-01-08 13:40 ` [PATCH 3/3] base85: Make the code more obvious instead of explaining the non-obvious Andreas Gruenbacher
3 siblings, 0 replies; 11+ messages in thread
From: Andreas Gruenbacher @ 2010-01-08 13:39 UTC (permalink / raw)
To: git; +Cc: Andreas Gruenbacher
Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
---
base85.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/base85.c b/base85.c
index b417a15..1d165d9 100644
--- a/base85.c
+++ b/base85.c
@@ -118,7 +118,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;
}
--
1.6.6.75.g37bae
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/3] base85: No need to initialize the decode table in encode_85
2010-01-07 17:58 ` Nicolas Pitre
2010-01-08 13:02 ` Andreas Gruenbacher
2010-01-08 13:39 ` [PATCH 1/3] base85 debug code: Fix length byte calculation Andreas Gruenbacher
@ 2010-01-08 13:39 ` Andreas Gruenbacher
2010-01-08 15:46 ` Michael J Gruber
2010-01-08 13:40 ` [PATCH 3/3] base85: Make the code more obvious instead of explaining the non-obvious Andreas Gruenbacher
3 siblings, 1 reply; 11+ messages in thread
From: Andreas Gruenbacher @ 2010-01-08 13:39 UTC (permalink / raw)
To: git; +Cc: Andreas Gruenbacher
Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
---
base85.c | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/base85.c b/base85.c
index 1d165d9..7204ce2 100644
--- a/base85.c
+++ b/base85.c
@@ -84,8 +84,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;
--
1.6.6.75.g37bae
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 2/3] base85: No need to initialize the decode table in encode_85
2010-01-08 13:39 ` [PATCH 2/3] base85: No need to initialize the decode table in encode_85 Andreas Gruenbacher
@ 2010-01-08 15:46 ` Michael J Gruber
2010-01-08 15:55 ` Junio C Hamano
0 siblings, 1 reply; 11+ messages in thread
From: Michael J Gruber @ 2010-01-08 15:46 UTC (permalink / raw)
To: Andreas Gruenbacher; +Cc: git
Andreas Gruenbacher venit, vidit, dixit 08.01.2010 14:39:
> Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
> ---
For the less informed it may be worthwhile to have an explanation in the
commit message why encode_85() does not need to initialize the table. (I
strongly suspect it's a matter of de vs. en, i.e. "because it only
encodes but does not decode."...)
> base85.c | 2 --
> 1 files changed, 0 insertions(+), 2 deletions(-)
>
> diff --git a/base85.c b/base85.c
> index 1d165d9..7204ce2 100644
> --- a/base85.c
> +++ b/base85.c
> @@ -84,8 +84,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;
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/3] base85: No need to initialize the decode table in encode_85
2010-01-08 15:46 ` Michael J Gruber
@ 2010-01-08 15:55 ` Junio C Hamano
2010-01-08 16:17 ` [PATCH] base85: encode85() does not use the decode table Andreas Gruenbacher
2010-01-08 16:22 ` [PATCH] base85: encode_85() " Andreas Gruenbacher
0 siblings, 2 replies; 11+ messages in thread
From: Junio C Hamano @ 2010-01-08 15:55 UTC (permalink / raw)
To: Michael J Gruber; +Cc: Andreas Gruenbacher, git
Michael J Gruber <git@drmicha.warpmail.net> writes:
> Andreas Gruenbacher venit, vidit, dixit 08.01.2010 14:39:
>> Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
>> ---
>
> For the less informed it may be worthwhile to have an explanation in the
> commit message why encode_85() does not need to initialize the table. (I
> strongly suspect it's a matter of de vs. en, i.e. "because it only
> encodes but does not decode."...)
The title can be reworded to
base85: encode85() does not use the decode table
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH] base85: encode85() does not use the decode table
2010-01-08 15:55 ` Junio C Hamano
@ 2010-01-08 16:17 ` Andreas Gruenbacher
2010-01-08 16:22 ` [PATCH] base85: encode_85() " Andreas Gruenbacher
1 sibling, 0 replies; 11+ messages in thread
From: Andreas Gruenbacher @ 2010-01-08 16:17 UTC (permalink / raw)
To: git; +Cc: Andreas Gruenbacher
Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
---
base85.c | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/base85.c b/base85.c
index 1d165d9..7204ce2 100644
--- a/base85.c
+++ b/base85.c
@@ -84,8 +84,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;
--
1.6.6.75.g37bae
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH] base85: encode_85() does not use the decode table
2010-01-08 15:55 ` Junio C Hamano
2010-01-08 16:17 ` [PATCH] base85: encode85() does not use the decode table Andreas Gruenbacher
@ 2010-01-08 16:22 ` Andreas Gruenbacher
1 sibling, 0 replies; 11+ messages in thread
From: Andreas Gruenbacher @ 2010-01-08 16:22 UTC (permalink / raw)
To: git; +Cc: Andreas Gruenbacher
Signed-off-by: Andreas Gruenbacher <agruen@suse.de>
---
base85.c | 2 --
1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/base85.c b/base85.c
index 1d165d9..7204ce2 100644
--- a/base85.c
+++ b/base85.c
@@ -84,8 +84,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;
--
1.6.6.75.g37bae
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 3/3] base85: Make the code more obvious instead of explaining the non-obvious
2010-01-07 17:58 ` Nicolas Pitre
` (2 preceding siblings ...)
2010-01-08 13:39 ` [PATCH 2/3] base85: No need to initialize the decode table in encode_85 Andreas Gruenbacher
@ 2010-01-08 13:40 ` Andreas Gruenbacher
2010-01-08 23:15 ` A Large Angry SCM
3 siblings, 1 reply; 11+ messages in thread
From: Andreas Gruenbacher @ 2010-01-08 13:40 UTC (permalink / raw)
To: git; +Cc: Andreas Gruenbacher
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
^ permalink raw reply related [flat|nested] 11+ messages in thread