-
Notifications
You must be signed in to change notification settings - Fork 552
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
Strange code fragments #406
Comments
badrishc
added a commit
that referenced
this issue
May 22, 2024
vazois
added a commit
that referenced
this issue
May 22, 2024
Re-opened pending addressing issue 5,6 in Tsavorite. |
TedHartMS
added a commit
that referenced
this issue
May 23, 2024
TedHartMS
added a commit
that referenced
this issue
May 23, 2024
chyin6
pushed a commit
to jusjin-org/garnet
that referenced
this issue
Jul 2, 2024
chyin6
pushed a commit
to jusjin-org/garnet
that referenced
this issue
Jul 2, 2024
* fix issues 3, 8, 9 * removed partially implemented or unused code --------- Co-authored-by: Badrish Chandramouli <badrishc@microsoft.com>
chyin6
pushed a commit
to jusjin-org/garnet
that referenced
this issue
Jul 2, 2024
…rosoft#416) Co-authored-by: Badrish Chandramouli <badrishc@microsoft.com>
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Describe the bug
Hello! I checked Garnet with the PVS-Studio static analyzer. I was wondering If you could take a look at several suspicious fragments:
Issue 1
Depending on the ternary operator condition, a null reference is assigned in the
sessionTransactionProcMap[id].Item1
tuple field. In addition, literally the next line later, the field is dereferenced without any check.Link to the method.
Issue 2
The analyzer has detected a case when an object is used after checking for
null
. It looks weird. I think this is an impossible case, and the?.
operator is redundant.Link to the method.
Issue 3
The
clusterConfig?.Nodes.ToArray()
expression is used as an argument of theInitClients
method. As a result,null
may be passed to the method. As we can see, in the first case of the switch operator, the parameter is dereferenced without checking fornull
.Link to the method.
Issue 4
The value obtained with the
?.
operator is assigned to theopPercent
andopWorkload
fields. Then, in the next line, these fields are used without checking fornull
.Link to the method.
Issue 5
Developer used the
?.
operator in this code fragment. Apparently, the programmer implied thatprevCtx
could have thenull
value. However, the thing is that foreach doesn't work withnull
.Link to the method.
Issue 6
In such a case, the analyzer shows that the condition of the ternary operator is always false. The
status
local variable is assigned a value withinif
. Let's look at two possible scenarios:OperationStatus.CANCELED
is assigned tostatus
;DoInternalLock
method is assigned tostatus
. If after that status equals toOperationStatus.SUCCESS
, thencontinue
is executed.So, at the moment of the ternary operator execution,
status
is never equal toOperationStatus.SUCCESS
, and the result of the ternary operator is always 0.Link to the method.
Issue 7
Developers use the ternary operator to assign different values to the
flushInterva
l field depending on whether the debugger is connected to the process or not. Because of the error, the value is the same regardless of the condition.Link to the method.
Issue 8
The developer writes the value to
lastVotedConfigEpoch
twice. Most likely, theCurrentConfigEpoch
property should've been used here instead.Link to the method.
Issue 9
Here, the analyzer shows that the
if
statement condition is always false. The thing is that theworkerId
property is of the ushort type. The possible range is 0 to 65535. This means thatworkerId
can't be less than 0.Link to the method.
Steps to reproduce the bug
No response
Expected behavior
No response
Screenshots
No response
Release version
No response
IDE
No response
OS version
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: