Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/libraries/System.Private.CoreLib/src/System/Convert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2527,16 +2527,16 @@ private static unsafe int ConvertToBase64Array(char* outChars, byte* inData, int

private static int ToBase64_CalculateAndValidateOutputLength(int inputLength, bool insertLineBreaks)
{
long outlen = ((long)inputLength) / 3 * 4; // the base length - we want integer division here.
outlen += ((inputLength % 3) != 0) ? 4 : 0; // at most 4 more chars for the remainder
// the base length - we want integer division here, at most 4 more chars for the remainder
long outlen = ((long)inputLength + 2) / 3 * 4;

if (outlen == 0)
return 0;

if (insertLineBreaks)
{
long newLines = outlen / base64LineBreakPosition;
if ((outlen % base64LineBreakPosition) == 0)
(long newLines, long remainder) = Math.DivRem(outlen, base64LineBreakPosition);
if (remainder == 0)
{
--newLines;
}
Expand Down