Add CA1514: Remove redundant length argument#6814
Merged
Merged
Conversation
This analyzer detects uses of Substring/Slice(start, length) that slice to the end of the buffer. In these cases, the length check is redundant, can be omitted, and the call can be replaced with Substring/Slice(start). The analyzer also detects if the evaluation of the instance or arguments can lead to side effects and does not flag these cases.
Codecov Report
@@ Coverage Diff @@
## main #6814 +/- ##
==========================================
- Coverage 96.42% 96.39% -0.03%
==========================================
Files 1398 1406 +8
Lines 333552 332375 -1177
Branches 11038 10923 -115
==========================================
- Hits 321624 320408 -1216
- Misses 9165 9212 +47
+ Partials 2763 2755 -8 |
buyaa-n
approved these changes
Sep 21, 2023
Thanks for broad testing, all looks valid and worth fixing. |
Co-authored-by: Buyaa Namnan <buyankhishig.namnan@microsoft.com>
Also use the new code fix title for the fixer and rerun msbuild pack.
Author
|
Thanks for the review @buyaa-n, I've addressed your review, merged main, and rerun |
Author
|
Seems like |
This was referenced Jul 28, 2025
Closed
Closed
This was referenced Aug 4, 2025
This was referenced Aug 25, 2025
This was referenced Oct 28, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes dotnet/runtime#68946.
This analyzer detects uses of
Substring/Slice(start, length)that slice to the end of the buffer.In these cases, the length check is redundant, can be omitted, and the call can be replaced with
Substring/Slice(start).The analyzer also detects if the evaluation of the instance or arguments can lead to side effects and does not flag these cases.
I have found no warning when running the analyzer against
dotnet/runtimeanddotnet/roslyn-analyzers, 1 warning indotnet/roslynand 8 warnings indotnet/aspnetcore:Not sure about the resource strings, would appreciate any suggestions.