Skip to content

Commit

Permalink
Fix codeql alerts.
Browse files Browse the repository at this point in the history
  • Loading branch information
nathan130200 committed Apr 12, 2024
1 parent e9eeebc commit 801c18b
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 30 deletions.
3 changes: 3 additions & 0 deletions XmppSharp/Dom/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ public async Task<bool> Advance()
await OnStreamEnd.InvokeAsync();
else
{
if (_context == null)
throw new JabberStreamException(StreamErrorCondition.InvalidXml, "The element in the current scope was not expected to be null.");

var parent = _context.Parent;

if (parent == null)
Expand Down
3 changes: 3 additions & 0 deletions XmppSharp/Exceptions/JabberStreamException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ public JabberStreamException(StreamErrorCondition condition) : base($"XMPP strea
/// <param name="innerException">Inner exception that may have caused the problem.</param>
public JabberStreamException(StreamErrorCondition condition, Exception innerException) : base($"XMPP stream error of type '{condition}' was thrown.", innerException)
=> Condition = condition;

public JabberStreamException(StreamErrorCondition condition, string message) : base(message)
=> Condition = condition;
}
18 changes: 4 additions & 14 deletions XmppSharp/Jid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,8 @@ public override int GetHashCode() => HashCode.Combine(
/// <returns><see langword="true"/> if both JIDs are equals, otherwise <see langword="false" />.</returns>
public static bool IsBareEquals(Jid lhs, Jid rhs)
{
if (rhs is null)
{
if (lhs is null)
return true;

return false;
}
if (lhs is null)
return rhs is null;

if (!lhs.IsBare || !rhs.IsBare)
return false;
Expand All @@ -264,13 +259,8 @@ public static bool IsBareEquals(Jid lhs, Jid rhs)
/// <returns><see langword="true"/> if both JIDs are equals, otherwise <see langword="false" />.</returns>
public static bool IsFullEqual(Jid lhs, Jid rhs)
{
if (rhs is null)
{
if (lhs is null)
return true;

return false;
}
if (lhs is null)
return rhs is null;

if (lhs.IsBare || rhs.IsBare)
return false;
Expand Down
5 changes: 1 addition & 4 deletions XmppSharp/Protocol/Sasl/Mechanisms.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ public IEnumerable<Mechanism> SupportedMechanisms
Elements().ForEach(n => n.Remove());

foreach (var item in value)
{
if (item != null)
Add(item);
}
Add(item);
}
}
public void AddMechanism(MechanismType type)
Expand Down
10 changes: 2 additions & 8 deletions XmppSharp/Protocol/ServiceDiscovery/DiscoInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ public IEnumerable<Identity> Identities
if (value != null)
{
foreach (var item in value)
{
if (item != null)
Add(item);
}
Add(item);
}
}
}
Expand All @@ -55,10 +52,7 @@ public IEnumerable<Feature> Features
if (value != null)
{
foreach (var feature in value)
{
if (feature != null)
Add(feature);
}
Add(feature);
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions XmppSharp/Protocol/ServiceDiscovery/DiscoItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ public IEnumerable<Item> Items
if (value != null)
{
foreach (var item in value)
{
if (item != null)
Add(item);
}
Add(item);
}
}
}
Expand Down

0 comments on commit 801c18b

Please sign in to comment.