You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unreachable code in Mono.Options GetArgumentName (always false do-while condition) #126538
Because j is exactly 0 at the end of the first iteration, the ternary operator j != 0 ? ... : false always evaluates to false. This means the loop guarantees to exit after the first iteration, making the check description [j++ - 1] == '{' completely unreachable dead code.
Since this code is quite old, we are unsure if the do-while loop was originally intended to perform a deeper search (and a variable increment is missing), or if the loop is simply redundant and can be safely replaced with a single IndexOf call.
Could you please take a look and advise if this needs a logic fix or just a cleanup?
Found by Linux Verification Center (linuxtesting.org) with SVACE.
GetArgumentName is used for when outputting help for a command-line option. It searches an Option.Description string for markup like {name} or {0:name} (or some other number) and then returns name. The purpose of the suspicious loop seems to be to ignore matches that are preceded by another opening brace, like {{name}. That does not work and the whole GetArgumentName method was rewritten in mono/mono#6506 to use regular expressions instead.
AFAICT, this copy of Mono.Options is used only in src/tools/illink/src/tlens/TLens/Driver.cs. There, the Option.Description strings do not include doubled opening braces so the bug has no effect.
I imagine the static analysis warning could be fixed by cherry-picking the change from Mono. I think that would be better than diverging from the upstream source by removing the double-opening-brace feature. Although regular expressions may be less efficient than hand-coded loops, it doesn't matter here because the method is called only for command-line help.
Activity
KalleOlaviNiemitalo commentedon Apr 5, 2026
You refer to this loop in
OptionSet.GetArgumentName:runtime/src/tools/illink/external/Mono.Options/Options.cs
Lines 1502 to 1506 in 937dec6
It originated in mono/mono@3e206c4#diff-d2a050f05daebe430e526b31f34e3f616b80774900673e21b524a57822bbc31aR990-R993.
It was copied to dotnet/linker in dotnet/linker@2e5c599#diff-f2ae5aec3d6f84439a0f15e836bcb9f2397a04461356a037a64fdf5cf51f9e51R1403-R1406 and from there to dotnet/runtime.
GetArgumentNameis used for when outputting help for a command-line option. It searches anOption.Descriptionstring for markup like{name}or{0:name}(or some other number) and then returnsname. The purpose of the suspicious loop seems to be to ignore matches that are preceded by another opening brace, like{{name}. That does not work and the wholeGetArgumentNamemethod was rewritten in mono/mono#6506 to use regular expressions instead.AFAICT, this copy of
Mono.Optionsis used only in src/tools/illink/src/tlens/TLens/Driver.cs. There, theOption.Descriptionstrings do not include doubled opening braces so the bug has no effect.I imagine the static analysis warning could be fixed by cherry-picking the change from Mono. I think that would be better than diverging from the upstream source by removing the double-opening-brace feature. Although regular expressions may be less efficient than hand-coded loops, it doesn't matter here because the method is called only for command-line help.
area-Tools-ILLink.NET linker development as well as trimming analyzers
might be more appropriate than
area-VM-meta-mono
.
MichalStrehovsky commentedon Apr 5, 2026
Moved to ILLink. If this is only used in tlens, I think the plan is to just delete tlens (#125275). We should make sure to delete Options.cs too.
dotnet-policy-service commentedon Apr 5, 2026
Tagging subscribers to this area: @agocke, @dotnet/illink
See info in area-owners.md if you want to be subscribed.
Delete orphaned Mono.Options/Options.cs and external directory (fixes #…