File tree 1 file changed +6
-8
lines changed
1 file changed +6
-8
lines changed Original file line number Diff line number Diff line change @@ -53,20 +53,18 @@ char *base64encode(const unsigned char *buf, size_t *size)
53
53
unsigned char input [3 ];
54
54
unsigned int output [4 ];
55
55
while (n < * size ) {
56
- input [0 ] = buf [n ++ ];
57
- input [1 ] = (n < * size ) ? buf [n ++ ] : 0 ;
58
- input [2 ] = (n < * size ) ? buf [n ++ ] : 0 ;
56
+ input [0 ] = buf [n ];
57
+ input [1 ] = (n + 1 < * size ) ? buf [n + 1 ] : 0 ;
58
+ input [2 ] = (n + 2 < * size ) ? buf [n + 2 ] : 0 ;
59
59
output [0 ] = input [0 ] >> 2 ;
60
60
output [1 ] = ((input [0 ] & 3 ) << 4 ) + (input [1 ] >> 4 );
61
61
output [2 ] = ((input [1 ] & 15 ) << 2 ) + (input [2 ] >> 6 );
62
62
output [3 ] = input [2 ] & 63 ;
63
63
outbuf [m ++ ] = base64_str [(int )output [0 ]];
64
64
outbuf [m ++ ] = base64_str [(int )output [1 ]];
65
- outbuf [m ++ ] = base64_str [(int )output [2 ]];
66
- outbuf [m ++ ] = base64_str [(int )output [3 ]];
67
- }
68
- while ((m % 4 ) != 0 ) {
69
- outbuf [m ++ ] = base64_pad ;
65
+ outbuf [m ++ ] = (n + 1 < * size ) ? base64_str [(int )output [2 ]] : base64_pad ;
66
+ outbuf [m ++ ] = (n + 2 < * size ) ? base64_str [(int )output [3 ]] : base64_pad ;
67
+ n += 3 ;
70
68
}
71
69
outbuf [m ] = 0 ; // 0-termination!
72
70
* size = m ;
You can’t perform that action at this time.
0 commit comments