mirror of
https://github.com/github/codeql.git
synced 2026-05-14 11:19:27 +02:00
C#: Adjust the extractor to correctly handle names for user defined increment and decrement operators.
This commit is contained in:
@@ -52,6 +52,13 @@ namespace Semmle.Extraction.CSharp.Util
|
||||
{ "op_False", "false" }
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// The operatorname for user-defined increment and decrement operators are "op_IncrementAssignment" and
|
||||
/// "op_DecrementAssignment" respectively.
|
||||
/// Thus we need to handle this explicitly to avoid postfixing them with an "=".
|
||||
/// </summary>
|
||||
private static bool isIncrementOrDecrement(string operatorName) => operatorName == "++" || operatorName == "--";
|
||||
|
||||
/// <summary>
|
||||
/// Convert an operator method name in to a symbolic name.
|
||||
/// A return value indicates whether the conversion succeeded.
|
||||
@@ -72,7 +79,7 @@ namespace Semmle.Extraction.CSharp.Util
|
||||
if (match.Success && methodToOperator.TryGetValue($"op_{match.Groups[2]}", out var rawOperatorName))
|
||||
{
|
||||
var prefix = match.Groups[1].Success ? "checked " : "";
|
||||
var postfix = match.Groups[3].Success ? "=" : "";
|
||||
var postfix = match.Groups[3].Success && !isIncrementOrDecrement(rawOperatorName) ? "=" : "";
|
||||
operatorName = $"{prefix}{rawOperatorName}{postfix}";
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user