kwset: use unsigned char to store values with high-bit set
Sun Studio on Solaris issues warnings about improper initialization values being used when defining tolower_trans_tbl[] in ctype.c. The array wants to store values with high-bit set and treat them as values between 128 to 255. Unlike the rest of the Git codebase where we explicitly specify 'unsigned char' for such variables and arrays, however, kwset code we borrowed from elsewhere uses 'char' for this and other variables. Fix the declarations to explicitly use 'unsigned char' where necessary to bring it in line with the rest of the Git. Signed-off-by: Ben Walton <bdwalton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ben Walton committed
Mar 2, 2015 at 19:22 UTC
189c860c9ec5deb95845c056ca5c15b58970158e
4 files changed
+7
-7
ctype.c
+1
-1
@@ -30,7 +30,7 @@ const unsigned char sane_ctype[256] = {
30
};
31
32
/* For case-insensitive kwset */
33
-const char tolower_trans_tbl[256] = {
33
+const unsigned char tolower_trans_tbl[256] = {
34
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
35
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
36
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
git-compat-util.h
+1
-1
@@ -554,7 +554,7 @@ static inline int has_extension(const char *filename, const char *ext)
554
}
555
556
/* in ctype.c, for kwset users */
557
-extern const char tolower_trans_tbl[256];
557
+extern const unsigned char tolower_trans_tbl[256];
558
559
/* Sane ctype - no locale, and works with signed chars */
560
#undef isascii
kwset.c
+4
-4
@@ -80,13 +80,13 @@ struct kwset
80
struct trie *next[NCHAR]; /* Table of children of the root. */
81
char *target; /* Target string if there's only one. */
82
int mind2; /* Used in Boyer-Moore search for one string. */
83
- char const *trans; /* Character translation table. */
83
+ unsigned char const *trans; /* Character translation table. */
84
};
85
86
/* Allocate and initialize a keyword set object, returning an opaque
87
pointer to it. Return NULL if memory is not available. */
88
kwset_t
89
-kwsalloc (char const *trans)
89
+kwsalloc (unsigned char const *trans)
90
{
91
struct kwset *kwset;
92
@@ -381,7 +381,7 @@ kwsprep (kwset_t kws)
381
register struct kwset *kwset;
382
register int i;
383
register struct trie *curr;
384
- register char const *trans;
384
+ register unsigned char const *trans;
385
unsigned char delta[NCHAR];
386
387
kwset = (struct kwset *) kws;
@@ -590,7 +590,7 @@ cwexec (kwset_t kws, char const *text, size_t len, struct kwsmatch *kwsmatch)
590
register int d;
591
register char const *end, *qlim;
592
register struct tree const *tree;
593
- register char const *trans;
593
+ register unsigned char const *trans;
594
595
accept = NULL;
596
kwset.h
+1
-1
@@ -39,7 +39,7 @@ typedef struct kwset_t* kwset_t;
39
if enough memory cannot be obtained. The argument if non-NULL
40
specifies a table of character translations to be applied to all
41
pattern and search text. */
42
-extern kwset_t kwsalloc(char const *);
42
+extern kwset_t kwsalloc(unsigned char const *);
43
44
/* Incrementally extend the keyword set to include the given string.
45
Return NULL for success, or an error message. Remember an index