Examples of errors detected by the V3137 diagnostic
V3137. The variable is assigned but is not used by the end of the function.
Files
V3137 The 'trackRingThickness' variable is assigned but is not used by the end of the function. Files.App.Controls StorageRing.cs 211
private void UpdateRadii(double newRadius, bool isTrack)
{
double valueRingThickness = _valueRingThickness;
double trackRingThickness = _trackRingThickness;
// Limit the Thickness values to no more than 1/5 of the container size
if (isTrack)
trackRingThickness = newRadius > (AdjustedSize / 5)
? (AdjustedSize / 5) : newRadius;
else
valueRingThickness = newRadius > (AdjustedSize / 5)
? (AdjustedSize / 5) : newRadius;
// If both Rings have Equal thickness, use 0;
// otherwise, use the larger thickness to adjust the size
double check = (AdjustedSize / 2) –
(_thicknessCheck is ThicknessCheck.Equal ? 0 : _largerThickness / 2);
double minSize = 4;
_sharedRadius = check <= minSize ? minSize : check;
}
Similar errors can be found in some other places:
- V3137 [CWE-563] The 'valueRingThickness' variable is assigned but is not used by the end of the function. Files.App.Controls StorageRing.cs 213
Windows Terminal
V3137 The 'fSuccess' variable is assigned but is not used by the end of the function. Program2.cs 80
public static void enableVT()
{
IntPtr hCon = Pinvoke.GetStdHandle(Pinvoke.STD_OUTPUT_HANDLE);
int mode;
bool fSuccess = Pinvoke.GetConsoleMode(hCon, out mode);
if (fSuccess)
{
mode |= Pinvoke.ENABLE_VIRTUAL_TERMINAL_PROCESSING;
fSuccess = Pinvoke.SetConsoleMode(hCon, mode);
}
}
Similar errors can be found in some other places:
- V3137 The 'fSuccess' variable is assigned but is not used by the end of the function. Program2.cs 92
Starlight
V3137 The 'obj' variable is assigned but is not used by the end of the function. VertexShakeB.cs 44
void ON_TEXT_CHANGED(Object obj)
{
if (obj = m_TextComponent)
hasTextChanged = true;
}
Power-Fx
V3137 [CWE-563] The 'fullType' variable is assigned but is not used by the end of the function. DType.cs 1350
public DType Add(DName name, DType type)
{
AssertValid();
Contracts.Assert(IsAggregate);
Contracts.Assert(name.IsValid);
type.AssertValid();
var fullType = this;
if (IsLazyType)
{
fullType = LazyTypeProvider.GetExpandedType(IsTable);
}
Contracts.Assert(!TypeTree.Contains(name));
var tree = TypeTree.SetItem(name, type);
var newType = new DType(Kind, tree, AssociatedDataSources,
DisplayNameProvider);
return newType;
}
AWS SDK for .NET
V3137 The 'platform' variable is assigned but is not used by the end of the function. InternalSDKUtils.netstandard.cs 70
private static string GetXamarinInformation()
{
var xamarinDevice = Type.GetType("Xamarin.Forms.Device, Xamarin.Forms.Core");
if (xamarinDevice == null)
{
return null;
}
var runtime = xamarinDevice.GetProperty("RuntimePlatform")
?.GetValue(null)
?.ToString() ?? "";
var idiom = xamarinDevice.GetProperty("Idiom")
?.GetValue(null)
?.ToString() ?? "";
var platform = runtime + idiom; // <=
if (string.IsNullOrEmpty(platform))
{
platform = UnknownPlatform;
}
return string.Format(CultureInfo.InvariantCulture,
"Xamarin_{0}",
"Xamarin"); // <=
}
Unity C# reference source code
V3137 The 'maxDist' variable is assigned but is not used by the end of the function. TreeAOImporter.cs 142
static int CountIntersections(....)
{
....
int hitLength = s_RayCastHits.Length;
float maxDist = 0;
if (hitLength > 0)
maxDist = s_RayCastHits[s_RayCastHits.Length - 1].distance;
physicsScene.Raycast(....);
if (s_RayCastHits.Length > 0)
{
float len = length - s_RayCastHits[0].distance;
if (len > maxDist)
{
maxDist = len; // <=
}
}
return hitLength + s_RayCastHits.Length;
}
MonoGame
V3137 The 'len' variable is assigned but is not used by the end of the function. MonoGame.Framework.DesktopGL(netstandard2.0) ConstantBuffer.cs 91
private void SetData(int offset, int rows, int columns, object data)
{
....
if(....)
{
....
}
else if (rows == 1 || (rows == 4 && columns == 4))
{
// take care of shader compiler optimization
int len = rows * columns * elementSize;
if (_buffer.Length - offset > len)
len = _buffer.Length - offset; // <=
Buffer.BlockCopy(data as Array,
0,
_buffer,
offset,
rows*columns*elementSize);
}
....
}
MonoGame
V3137 The 'relativeVelocity' variable is assigned but is not used by the end of the function. MonoGame.Framework.DesktopGL(netstandard2.0) Cue.cs 266
public void Apply3D(AudioListener listener, AudioEmitter emitter)
{
....
lock (_engine.UpdateLock)
{
....
// Calculate doppler effect.
var relativeVelocity = emitter.Velocity - listener.Velocity;
relativeVelocity *= emitter.DopplerScale;
}
}
Umbraco
V3137 The 'username' variable is assigned but is not used by the end of the function. MemberManager.cs 87
public async Task<bool> IsMemberAuthorizedAsync(....)
{
....
if (IsLoggedIn() == false)
{
allowAction = false;
}
else
{
string username;
....
username = currentMember.UserName;
IList<string> allowTypesList = allowTypes as IList<string> ??
allowTypes.ToList();
if (allowTypesList.Any(allowType => allowType != string.Empty))
{
allowAction = allowTypesList.Select(x => x.ToLowerInvariant())
.Contains(currentMember
.MemberTypeAlias
.ToLowerInvariant());
}
if (allowAction && allowMembers.Any())
{
allowAction = allowMembers.Contains(memberId);
}
....
}
return allowAction;
}
LINQ to DB
V3137 The 'version' variable is assigned but is not used by the end of the function. Query.cs 408
public void TryAdd(IDataContext dataContext, Query<T> query, QueryFlags flags)
{
QueryCacheEntry[] cache;
int version;
lock (_syncCache)
{
cache = _cache;
version = _version;
}
....
lock(_syncCash)
{
....
var versionsDiff = _version - version;
....
_cache = newCache;
_indexes = newPriorities;
version = _version;
}
}
Similar errors can be found in some other places:
- V3137 The 'leftContext' variable is assigned but is not used by the end of the function. ExpressionBuilder.SqlBuilder.cs 1989
Telerik UI for UWP
V3137 The 'leftMargin' variable is assigned but is not used by the end of the function. DragDrop.cs 87
internal static void StartDrag(....)
{
....
if (frameworkElementSource != null)
{
leftMargin = frameworkElementSource.Margin.Left; // <=
topMargin = frameworkElementSource.Margin.Top; // <=
}
if (dragDropElement == null ||
!dragDropElement.CanStartDrag(trigger, initializeContext))
{
return;
}
var context = dragDropElement
.DragStarting(trigger, initializeContext);
if (context == null)
{
return;
}
var startDragPosition = e.GetCurrentPoint(context.DragSurface.RootElement)
.Position;
var relativeStartDragPosition = e.GetCurrentPoint(uiDragDropElement)
.Position;
var dragPositionMode = DragDrop.GetDragPositionMode(uiDragDropElement);
AddOperation(new DragDropOperation(context,
dragDropElement,
dragPositionMode,
e.Pointer,
startDragPosition,
relativeStartDragPosition));
}
Similar errors can be found in some other places:
- V3137 The 'topMargin' variable is assigned but is not used by the end of the function. DragDrop.cs 88
- V3137 The 'currentColumnLength' variable is assigned but is not used by the end of the function. WrapLayout.cs 824
Azure PowerShell
V3137 The 'apiVersionSetId' variable is assigned but is not used by the end of the function. GetAzureApiManagementApiVersionSet.cs 69
public String ApiVersionSetId { get; set; }
....
public override void ExecuteApiManagementCmdlet()
{
....
string apiVersionSetId;
if (ParameterSetName.Equals(ContextParameterSet))
{
....
apiVersionSetId = ApiVersionSetId;
}
else
{
apiVersionSetId = ....;
}
if (string.IsNullOrEmpty(ApiVersionSetId)) // <=
{
WriteObject(....);
}
else
{
WriteObject(Client.GetApiVersionSet(...., ApiVersionSetId)) // <=
}
}
Similar errors can be found in some other places:
- V3137 The 'cacheId' variable is assigned but is not used by the end of the function. RemoveAzureApiManagementCache.cs 94
Roslyn Analyzers
V3137 The 'sourceOrigins' variable is assigned but is not used by the end of the function. TaintedDataAnalysis.TaintedDataOperationVisitor.cs 328
public override TaintedDataAbstractValue VisitArrayInitializer(
IArrayInitializerOperation operation,
object argument)
{
HashSet<SymbolAccess> sourceOrigins = null;
....
if (baseAbstractValue.Kind == TaintedDataAbstractValueKind.Tainted)
{
sourceOrigins = new HashSet<SymbolAccess>(....);
}
....
}