Merge pull request #5612 from kareem-wolfssl/base16Ending

Update Base16_Encode so the ending null terminator is optional.
pull/5625/head
John Safranek 2022-09-22 13:24:19 -07:00 committed by GitHub
commit f113e92495
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 3 deletions

View File

@ -563,7 +563,7 @@ int Base16_Encode(const byte* in, word32 inLen, byte* out, word32* outLen)
if (in == NULL || out == NULL || outLen == NULL)
return BAD_FUNC_ARG;
if (*outLen < (2 * inLen + 1))
if (*outLen < (2 * inLen))
return BAD_FUNC_ARG;
for (i = 0; i < inLen; i++) {
@ -584,8 +584,9 @@ int Base16_Encode(const byte* in, word32 inLen, byte* out, word32* outLen)
out[outIdx++] = lb;
}
/* force 0 at this end */
out[outIdx++] = 0;
/* If the output buffer has a room for an extra byte, add a null terminator */
if (*outLen > outIdx)
out[outIdx++]= '\0';
*outLen = outIdx;
return 0;