Skip to content

Commit 20698a5

Browse files
committed
Attempt to be better with signed conversions
Most targets use unsigned chars. Explicitly change the static tables to `signed char`. An alternative would be to force signed chars during the compilation of libdispatch. When building for Linux AArch64, the use of `-1` causes signed conversion warnings when initializing the table.
1 parent 9ec74ed commit 20698a5

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/transform.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,21 @@ enum {
5959
static const unsigned char base32_encode_table[] =
6060
"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
6161

62-
static const char base32_decode_table[] = {
62+
static const signed char base32_decode_table[] = {
6363
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
6464
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
6565
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26,
6666
27, 28, 29, 30, 31, -1, -1, -1, -1, -1, -2, -1, -1, -1, 0, 1, 2,
6767
3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
6868
20, 21, 22, 23, 24, 25
6969
};
70-
static const ssize_t base32_decode_table_size = sizeof(base32_decode_table)
71-
/ sizeof(*base32_decode_table);
70+
static const ssize_t base32_decode_table_size =
71+
sizeof(base32_decode_table) / sizeof(*base32_decode_table);
7272

7373
static const unsigned char base32hex_encode_table[] =
7474
"0123456789ABCDEFGHIJKLMNOPQRSTUV";
7575

76-
static const char base32hex_decode_table[] = {
76+
static const signed char base32hex_decode_table[] = {
7777
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
7878
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
7979
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2,
@@ -87,7 +87,7 @@ static const ssize_t base32hex_decode_table_size =
8787
static const unsigned char base64_encode_table[] =
8888
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
8989

90-
static const char base64_decode_table[] = {
90+
static const signed char base64_decode_table[] = {
9191
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
9292
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
9393
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
@@ -99,8 +99,8 @@ static const char base64_decode_table[] = {
9999
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
100100
};
101101

102-
static const ssize_t base64_decode_table_size = sizeof(base64_decode_table)
103-
/ sizeof(*base64_decode_table);
102+
static const ssize_t base64_decode_table_size =
103+
sizeof(base64_decode_table) / sizeof(*base64_decode_table);
104104

105105
#pragma mark -
106106
#pragma mark dispatch_transform_buffer
@@ -555,7 +555,7 @@ _dispatch_transform_to_utf16be(dispatch_data_t data)
555555

556556
static dispatch_data_t
557557
_dispatch_transform_from_base32_with_table(dispatch_data_t data,
558-
const char* table, ssize_t table_size)
558+
const signed char* table, ssize_t table_size)
559559
{
560560
__block uint64_t x = 0, count = 0, pad = 0;
561561

@@ -585,7 +585,7 @@ _dispatch_transform_from_base32_with_table(dispatch_data_t data,
585585
}
586586
count++;
587587

588-
char value = table[index];
588+
signed char value = table[index];
589589
if (value == -2) {
590590
value = 0;
591591
pad++;
@@ -830,7 +830,7 @@ _dispatch_transform_from_base64(dispatch_data_t data)
830830
}
831831
count++;
832832

833-
char value = base64_decode_table[index];
833+
signed char value = base64_decode_table[index];
834834
if (value == -2) {
835835
value = 0;
836836
pad++;

0 commit comments

Comments
 (0)