Skip to content

Commit 5d6e853

Browse files
committed
refactor
1 parent ae2215d commit 5d6e853

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

Diff for: base64.c

+20-20
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ enum special_e {
2626
};
2727

2828
/** Lookup table that converts a base64 digit to integer. */
29-
static unsigned char const digittobin[] = {
29+
static char const digittobin[] = {
3030
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
3131
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
3232
64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
@@ -49,34 +49,34 @@ static unsigned char const digittobin[] = {
4949
/* Convert a base64 null-terminated string to binary format.*/
5050
void* b64tobin( void* dest, char const* src ) {
5151
unsigned char const* s = (unsigned char*)src;
52-
unsigned char* p = (unsigned char*)dest;
52+
char* p = dest;
5353
for(;;) {
5454

55-
unsigned int const a = digittobin[ *s ];
55+
int const a = digittobin[ *s ];
5656
if ( a == notabase64 ) return p;
5757
if ( a == terminator ) return p;
5858

59-
unsigned int const b = digittobin[ *++s ];
59+
int const b = digittobin[ *++s ];
6060
if ( b == notabase64 ) return 0;
6161
if ( b == terminator ) return 0;
6262

63-
*p++ = ( a << 2 ) | ( b >> 4 );
63+
*p++ = ( a << 2u ) | ( b >> 4u );
6464

65-
unsigned int const c = digittobin[ *++s ];
65+
int const c = digittobin[ *++s ];
6666
if ( c == notabase64 ) return 0;
6767

68-
unsigned int const d = digittobin[ *++s ];
68+
int const d = digittobin[ *++s ];
6969
if ( d == notabase64 ) return 0;
7070
if ( c == terminator ) {
7171
if ( d != terminator ) return 0;
7272
return p;
7373
}
7474

75-
*p++ = ( b << 4 ) | ( c >> 2 );
75+
*p++ = ( b << 4u ) | ( c >> 2u );
7676

7777
if ( d == terminator ) return p;
7878

79-
*p++ = ( c << 6 ) | ( d >> 0 );
79+
*p++ = ( c << 6u ) | ( d >> 0u );
8080
++s;
8181
}
8282

@@ -92,19 +92,19 @@ static char const bintodigit[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
9292
/** Get the first base 64 digit of a block of 4.
9393
* @param a The first byte of the source block of 3.
9494
* @return A base 64 digit. */
95-
static unsigned int get0( unsigned int a ) {
96-
unsigned int const index = a >> 2;
95+
static int get0( int a ) {
96+
int const index = a >> 2u;
9797
return bintodigit[ index ];
9898
}
9999

100100
/** Get the second base 64 digit of a block of 4.
101101
* @param a The first byte of the source block of 3.
102102
* @param b The second byte of the source block of 3.
103103
* @return A base 64 digit. */
104-
static unsigned int get1( unsigned int a, unsigned int b ) {
105-
unsigned int const indexA = ( a & 0b11 ) << 4;
106-
unsigned int const indexB = b >> 4;
107-
unsigned int const index = indexA | indexB;
104+
static int get1( int a, int b ) {
105+
int const indexA = ( a & 0b11 ) << 4u;
106+
int const indexB = b >> 4u;
107+
int const index = indexA | indexB;
108108
return bintodigit[ index ];
109109
}
110110

@@ -113,17 +113,17 @@ static unsigned int get1( unsigned int a, unsigned int b ) {
113113
* @param c The third byte of the source block of 3.
114114
* @return A base 64 digit. */
115115
static unsigned int get2( unsigned int b, unsigned int c ) {
116-
unsigned int const indexB = ( b & 0b1111 ) << 2;
117-
unsigned int const indexC = c >> 6;
118-
unsigned int const index = indexB | indexC;
116+
int const indexB = ( b & 0b1111 ) << 2u;
117+
int const indexC = c >> 6u;
118+
int const index = indexB | indexC;
119119
return bintodigit[ index ];
120120
}
121121

122122
/** Get the fourth base 64 digit of a block of 4.
123123
* @param c The third byte of the source block of 3.
124124
* @return A base 64 digit. */
125-
static unsigned int get3( unsigned int c ) {
126-
unsigned int const index = c & 0x3f;
125+
static int get3( int c ) {
126+
int const index = c & 0x3f;
127127
return bintodigit[ index ];
128128
}
129129

0 commit comments

Comments
 (0)