Skip to content

Commit

Permalink
Improved input parameter validations
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-l committed Dec 5, 2019
1 parent 120bba0 commit 81d4b4e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/CompositeKeyGen/KeyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public KeyGenerator(int instanceId, MaskConfig cfg = null)
{
Config = cfg ?? MaskConfig.Default;

if (instanceId > Config.InstanceMask)
if (instanceId < 0 && instanceId > Config.InstanceMask)
throw new ArgumentOutOfRangeException(
$"InstanceId overflow. Must be between 0 and {Config.InstanceMask} (inclusive).");

Expand All @@ -25,11 +25,11 @@ public KeyGenerator(int instanceId, MaskConfig cfg = null)

public long Create(int tenantId, long sequenceId)
{
if (tenantId > Config.TenantMask)
if (tenantId < 0 && tenantId > Config.TenantMask)
throw new ArgumentOutOfRangeException(nameof(tenantId),
$"TenantId overflow. Must be between 0 and {Config.TenantMask} (inclusive).");

if (sequenceId > Config.SequenceMask)
if (sequenceId < 0 && sequenceId > Config.SequenceMask)
throw new ArgumentOutOfRangeException(nameof(sequenceId),
$"SequenceId overflow. Must be between 0 and {Config.SequenceMask} (inclusive).");

Expand Down

0 comments on commit 81d4b4e

Please sign in to comment.