Skip to content

Commit

Permalink
Fix diagnostics found with new analyzer - CA1853 (#79896)
Browse files Browse the repository at this point in the history
* Update src/libraries/System.Reflection.Metadata/src/System/Reflection/PortableExecutable/DebugDirectory/DebugDirectoryBuilder.cs

Co-authored-by: Dan Moseley <[email protected]>
  • Loading branch information
buyaa-n and danmoseley authored Dec 22, 2022
1 parent 83d3daa commit 9fbb4ef
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ internal static void ParseToken(ref string q, string token, string op, ref bool
// Next character should be the operator if any
if (op != null)
{
if (0 != q.IndexOf(op, StringComparison.Ordinal))
if (!q.StartsWith(op, StringComparison.Ordinal))
throw new ArgumentException(SR.InvalidQuery); // Invalid query

// Strip off the op and any leading WS
Expand Down Expand Up @@ -1666,7 +1666,7 @@ protected internal override void ParseQuery(string query)
q = q.Remove(0, TokenOf.Length).TrimStart(null);

// Next character should be "{"
if (0 != q.IndexOf('{'))
if (!q.StartsWith('{'))
throw new ArgumentException(SR.InvalidQuery); // Invalid query

// Strip off the "{" and any leading WS
Expand Down Expand Up @@ -2183,7 +2183,7 @@ protected internal override void ParseQuery(string query)
q = q.Remove(0, TokenOf.Length).TrimStart(null);

// Next character should be "{"
if (0 != q.IndexOf('{'))
if (!q.StartsWith('{'))
throw new ArgumentException(SR.InvalidQuery); // Invalid query

// Strip off the "{" and any leading WS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void AddCodeViewEntry(
}

// We allow NUL characters to allow for padding for backward compat purposes.
if (pdbPath.Length == 0 || pdbPath.IndexOf('\0') == 0)
if (pdbPath.Length == 0 || pdbPath[0] == '\0')
{
Throw.InvalidArgument(SR.ExpectedNonEmptyString, nameof(pdbPath));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal ObjectToken OpenToken(string keyName)
{
// Check if the token is for a voice
string tokenName = keyName;
if (!string.IsNullOrEmpty(tokenName) && tokenName.IndexOf("HKEY_", StringComparison.Ordinal) != 0)
if (!string.IsNullOrEmpty(tokenName) && !tokenName.StartsWith("HKEY_", StringComparison.Ordinal))
{
tokenName = string.Format(CultureInfo.InvariantCulture, @"{0}\Tokens\{1}", Id, tokenName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ internal void CloneSubGraph(Rule rule, Backend org, Backend extra, Dictionary<St
string ruleName;

// Check for DYNAMIC grammars
if (arc.RuleRef.Name.IndexOf("URL:DYNAMIC#", StringComparison.Ordinal) == 0)
if (arc.RuleRef.Name.StartsWith("URL:DYNAMIC#", StringComparison.Ordinal))
{
ruleName = arc.RuleRef.Name.Substring(12);
if (fromOrg && FindInRules(ruleName) == null)
Expand All @@ -589,7 +589,7 @@ internal void CloneSubGraph(Rule rule, Backend org, Backend extra, Dictionary<St
CloneSubGraph(ruleExtra, org, extra, srcToDestHash, false);
}
}
else if (arc.RuleRef.Name.IndexOf("URL:STATIC#", StringComparison.Ordinal) == 0)
else if (arc.RuleRef.Name.StartsWith("URL:STATIC#", StringComparison.Ordinal))
{
ruleName = arc.RuleRef.Name.Substring(11);
if (fromOrg == false && FindInRules(ruleName) == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1847,7 +1847,7 @@ private void ValidateRulerefNotPointingToSelf(string uri)
// in srgs.xml: or <ruleref uri="srgs.xml>
if (_filename != null)
{
if (uri.IndexOf(_shortFilename, StringComparison.Ordinal) == 0 && (uri.Length > _shortFilename.Length && uri[_shortFilename.Length] == '#' || uri.Length == _shortFilename.Length))
if (uri.StartsWith(_shortFilename, StringComparison.Ordinal) && (uri.Length > _shortFilename.Length && uri[_shortFilename.Length] == '#' || uri.Length == _shortFilename.Length))
{
ThrowSrgsException(SRID.InvalidRuleRefSelf);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ internal override void Validate(SrgsGrammar grammar)
if (sUri[0] == '#')
{
bool uriFound = false;
if (sUri.IndexOf("#grammar:dictation", StringComparison.Ordinal) == 0 || sUri.IndexOf("#grammar:dictation#spelling", StringComparison.Ordinal) == 0)
if (sUri.StartsWith("#grammar:dictation", StringComparison.Ordinal))
{
uriFound = true;
}
Expand Down

0 comments on commit 9fbb4ef

Please sign in to comment.