From 192a6be2a77ab3bf446237fdf6575b0aca863d9e Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Wed, 30 May 2007 10:32:19 -0700 Subject: fix signed range problems with hex conversions Make hexval_table[] "const". Also make sure that the accessor function hexval() does not access the table with out-of-range values by declaring its parameter "unsigned char", instead of "unsigned int". With this, gcc can just generate: movzbl (%rdi), %eax movsbl hexval_table(%rax),%edx movzbl 1(%rdi), %eax movsbl hexval_table(%rax),%eax sall $4, %edx orl %eax, %edx for the code to generate a byte from two hex characters. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- cache.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cache.h') diff --git a/cache.h b/cache.h index 7cedda684..bea8cad5b 100644 --- a/cache.h +++ b/cache.h @@ -302,8 +302,8 @@ extern int legacy_loose_object(unsigned char *); extern int has_pack_file(const unsigned char *sha1); extern int has_pack_index(const unsigned char *sha1); -extern signed char hexval_table[256]; -static inline unsigned int hexval(unsigned int c) +extern const signed char hexval_table[256]; +static inline unsigned int hexval(unsigned char c) { return hexval_table[c]; } -- cgit v1.2.1