Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix diagnostics found with new analyzer - CA1858 #79896

Merged
merged 3 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
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,12 @@ 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 ||
#if NETCOREAPP
pdbPath.StartsWith('\0'))
#else
pdbPath[0] == '\0')
#endif
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
buyaa-n marked this conversation as resolved.
Show resolved Hide resolved
{
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