@matheusbsbs / matheus-bagliano / commits / 192a6be2a7
Fork 0

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 <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed May 30, 2007 at 10:32 UTC 192a6be2a77ab3bf446237fdf6575b0aca863d9e
2 files changed +3 -3
cache.h
+2 -2
@@ -302,8 +302,8 @@ extern int legacy_loose_object(unsigned char *);
302 extern int has_pack_file(const unsigned char *sha1);
303 extern int has_pack_index(const unsigned char *sha1);
304
305 -extern signed char hexval_table[256];
306 -static inline unsigned int hexval(unsigned int c)
305 +extern const signed char hexval_table[256];
306 +static inline unsigned int hexval(unsigned char c)
307 {
308 return hexval_table[c];
309 }
sha1_file.c
+1 -1
@@ -32,7 +32,7 @@ const unsigned char null_sha1[20];
32
33 static unsigned int sha1_file_open_flag = O_NOATIME;
34
35 -signed char hexval_table[256] = {
35 +const signed char hexval_table[256] = {
36 -1, -1, -1, -1, -1, -1, -1, -1, /* 00-07 */
37 -1, -1, -1, -1, -1, -1, -1, -1, /* 08-0f */
38 -1, -1, -1, -1, -1, -1, -1, -1, /* 10-17 */