Skip to content

Commit

Permalink
lib: use proper unsigned type for walking string
Browse files Browse the repository at this point in the history
Use a pointer to unsigned char as the type of variable to walk the
string and write the output. Important since we know that character
values can be over 127, and we use the value as an index into a 256-part
array during decoding. After this change, we can also remove some ugly
typecasts.
  • Loading branch information
aklomp committed Aug 18, 2015
1 parent f637b70 commit a3bd06c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/dec/head.c
@@ -1,6 +1,6 @@
int ret = 0;
const char *c = src;
char *o = out;
const unsigned char *c = (const unsigned char *)src;
unsigned char *o = (unsigned char *)out;
unsigned char q;

/* Use local temporaries to avoid cache thrashing: */
Expand Down
8 changes: 4 additions & 4 deletions lib/dec/tail.c
Expand Up @@ -2,7 +2,7 @@
ret = 1;
break;
}
if ((q = base64_table_dec[(unsigned char)*c++]) >= 254) {
if ((q = base64_table_dec[*c++]) >= 254) {
st.eof = 1;
/* Treat character '=' as invalid for byte 0: */
break;
Expand All @@ -14,7 +14,7 @@
ret = 1;
break;
}
if ((q = base64_table_dec[(unsigned char)*c++]) >= 254) {
if ((q = base64_table_dec[*c++]) >= 254) {
st.eof = 1;
/* Treat character '=' as invalid for byte 1: */
break;
Expand All @@ -28,7 +28,7 @@
ret = 1;
break;
}
if ((q = base64_table_dec[(unsigned char)*c++]) >= 254) {
if ((q = base64_table_dec[*c++]) >= 254) {
st.eof = 1;
/* When q == 254, the input char is '='. Return 1 and EOF.
* Technically, should check if next byte is also '=', but never mind.
Expand All @@ -45,7 +45,7 @@
ret = 1;
break;
}
if ((q = base64_table_dec[(unsigned char)*c++]) >= 254) {
if ((q = base64_table_dec[*c++]) >= 254) {
st.eof = 1;
/* When q == 254, the input char is '='. Return 1 and EOF.
* When q == 255, the input char is invalid. Return 0 and EOF. */
Expand Down
4 changes: 2 additions & 2 deletions lib/enc/head.c
@@ -1,7 +1,7 @@
/* Assume that *out is large enough to contain the output.
* Theoretically it should be 4/3 the length of src. */
const unsigned char *c = (unsigned char *)src;
char *o = out;
const unsigned char *c = (const unsigned char *)src;
unsigned char *o = (unsigned char *)out;

/* Use local temporaries to avoid cache thrashing: */
size_t outl = 0;
Expand Down

0 comments on commit a3bd06c

Please sign in to comment.