Skip to content
Prev Previous commit
Next Next commit
Updated argument check exceptions
  • Loading branch information
sboshra committed Nov 1, 2024
commit 1f544ea3777fc3487d15441c99ed2a8facebf7e2
20 changes: 8 additions & 12 deletions Microsoft.Azure.Cosmos/src/Json/JsonWriter.JsonBinaryWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -997,15 +997,13 @@ static private bool TryWriteUniformNumberArray(
int valueLength,
int itemCount)
{
if (arrayWriter == null) throw new ArgumentNullException($"{nameof(arrayWriter)}");
if (arrayWriter == null) throw new ArgumentNullException(nameof(arrayWriter));
if (byteCount <= 0) throw new ArgumentException($"Value must be greater than 0.", nameof(byteCount));
if (valueLength <= 0) throw new ArgumentException($"Value must be greater than 0.", nameof(valueLength));

// Uniform arrays only support 1 and 2-byte item count
if (itemCount > ushort.MaxValue) return false;

// DOCDBASSERT(TypeMarker.IsArray(m_pbyBuffer[startOffset]));
// DOCDBASSERT(byteCount > 0);
// DOCDBASSERT(valueLength > 0);

int floatCount = 0;
long maxValue = long.MinValue;
long minValue = long.MaxValue;
Expand Down Expand Up @@ -1046,8 +1044,8 @@ static private bool TryWriteUniformNumberArray(
arrayBuffer = arrayBuffer.Slice(itemLength);
}

// DOCDBASSERT(numberValues.GetCount() == itemCount);
// DOCDBASSERT(itemCount >= floatCount);
// Assert(numberValues.Count == itemCount);
// Assert(itemCount >= floatCount);

byte itemTypeMarker;
int itemSize;
Expand Down Expand Up @@ -1179,16 +1177,14 @@ static private bool TryWriteUniformArrayOfNumberArrays(
int valueLength,
int itemCount)
{
if (arrayWriter == null) throw new ArgumentNullException($"{nameof(arrayWriter)}");
if (arrayWriter == null) throw new ArgumentNullException(nameof(arrayWriter));
if (byteCount <= 0) throw new ArgumentException($"Value must be greater than 0.", nameof(byteCount));
if (valueLength <= 0) throw new ArgumentException($"Value must be greater than 0.", nameof(valueLength));

// Uniform arrays only support 1 and 2-byte item count
if (itemCount > ushort.MaxValue) return false;
if (itemCount < 2) return false;

// DOCDBASSERT(TypeMarker::IsArray(m_pbyBuffer[nStartOffset]));
// DOCDBASSERT(nByteCount > 0);
// DOCDBASSERT(nValueLength > 0);

UniformArrayInfo commonArrayInfo = default;
int commonArrayLength = 0;

Expand Down