# Re: [PATCH 1/2] use SHA_DIGEST_LENGTH

1 messages from 2006-09-24 to 2006-09-24. Participants: David Rientjes.
Thread: https://gitlist.dev/t/5670

## David Rientjes, 2006-09-24 03:33

Subject: Re: [PATCH 1/2] use SHA_DIGEST_LENGTH
Message-ID: <Pine.LNX.4.64N.0609232028290.14996@attu4.cs.washington.edu>
URL: https://gitlist.dev/e/Pine.LNX.4.64N.0609232028290.14996%40attu4.cs.washington.edu
In-Reply-To: <Pine.LNX.4.64N.0609232011050.14284@attu4.cs.washington.edu>

```
On Sat, 23 Sep 2006, David Rientjes wrote:

> @@ -202,16 +202,17 @@ int cmd_name_rev(int argc, const char **
>  #define ishex(x) (isdigit((x)) || ((x) >= 'a' && (x) <= 'f'))
>  				if (!ishex(*p))
>  					forty = 0;
> -				else if (++forty == 40 &&
> +				else if (++forty == 2 * SHA_DIGEST_LENGTH &&
>  						!ishex(*(p+1))) {
> -					unsigned char sha1[40];
> +					unsigned char sha1[2 * SHA_DIGEST_LENGTH];
>  					const char *name = "undefined";
>  					char c = *(p+1);
>  
>  					forty = 0;
>  
>  					*(p+1) = 0;
> -					if (!get_sha1(p - 39, sha1)) {
> +					if (!get_sha1(p - (SHA_DIGEST_LENGTH + 1),
> +						      sha1)) {
>  						struct object *o =
>  							lookup_object(sha1);
>  						if (o)

Off by 18 error.

Signed-off-by: David Rientjes <rientjes@cs.washington.edu>
---
 builtin-name-rev.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/builtin-name-rev.c b/builtin-name-rev.c
index f522664..ed99679 100644
--- a/builtin-name-rev.c
+++ b/builtin-name-rev.c
@@ -211,7 +211,7 @@ #define ishex(x) (isdigit((x)) || ((x) >
 					forty = 0;
 
 					*(p+1) = 0;
-					if (!get_sha1(p - (SHA_DIGEST_LENGTH + 1),
+					if (!get_sha1(p - 2 * SHA_DIGEST_LENGTH + 1,
 						      sha1)) {
 						struct object *o =
 							lookup_object(sha1);

```
