Skip to content

Attempt to be better with signed conversions #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/transform.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@ enum {
static const unsigned char base32_encode_table[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";

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

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

static const char base32hex_decode_table[] = {
static const signed char base32hex_decode_table[] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2,
Expand All @@ -87,7 +87,7 @@ static const ssize_t base32hex_decode_table_size =
static const unsigned char base64_encode_table[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

static const char base64_decode_table[] = {
static const signed char base64_decode_table[] = {
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Expand All @@ -99,8 +99,8 @@ static const char base64_decode_table[] = {
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
};

static const ssize_t base64_decode_table_size = sizeof(base64_decode_table)
/ sizeof(*base64_decode_table);
static const ssize_t base64_decode_table_size =
sizeof(base64_decode_table) / sizeof(*base64_decode_table);

#pragma mark -
#pragma mark dispatch_transform_buffer
Expand Down Expand Up @@ -555,7 +555,7 @@ _dispatch_transform_to_utf16be(dispatch_data_t data)

static dispatch_data_t
_dispatch_transform_from_base32_with_table(dispatch_data_t data,
const char* table, ssize_t table_size)
const signed char* table, ssize_t table_size)
{
__block uint64_t x = 0, count = 0, pad = 0;

Expand Down Expand Up @@ -585,7 +585,7 @@ _dispatch_transform_from_base32_with_table(dispatch_data_t data,
}
count++;

char value = table[index];
signed char value = table[index];
if (value == -2) {
value = 0;
pad++;
Expand Down Expand Up @@ -830,7 +830,7 @@ _dispatch_transform_from_base64(dispatch_data_t data)
}
count++;

char value = base64_decode_table[index];
signed char value = base64_decode_table[index];
if (value == -2) {
value = 0;
pad++;
Expand Down