Issues with the Base64 encoding zero fill padding pattern

Unfortunately it was taken from the same code base and the code in lines 55 to 69 is a bit confused:

55  if(i){
56          for(uint8_t j = i; j < 3; j++){
57              a3[j] = '\0';
58          }
59  
60          a3to4(a3, a4);
61  
62          for(uint8_t j = 0; j < i + 1; j++){
63              *output++ = alphaTable[a4[j]];
64          }
65  
66          while(i++ < 3){
67              *output++ = '=';
68          }
69      }
72  }

Fullfilling a3 with zeros (in lines 56 to 58) results in some useless 'A's being added to the output.
(alphaTable[0] = 0x41 = 65 = ASCII index for A).
This is because that increasing by 1 in line 62 results in an addition of surely one 'A' - in some cases two 'A's - to the output.
The padding with equal signs, which is actually exclusively required, is additionally executed (lines 66 to 69).

User: 'admin', password: 'esp32'
www-authorization: 'basic YWRtaW46ZXNwMzI='
BASE64::encode generates 'YWRtaW46ZXNwMzIA'

User: 'admin', password: 'esp3'
www-authorization: 'basic YWRtaW46ZXNwMw=='
BASE64::encode generates 'YWRtaW46ZXNwMwA='

User: 'admin', password: 'esp'
www-authorization: 'basic YWRtaW46ZXNw'
BASE64::encode generates 'YWRtaW46ZXNwAA=='