Skip to content
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

AVM: Simplify conversion and fix a spurious complaint from static analysis #5421

Merged
merged 2 commits into from
May 26, 2023

Conversation

jannotti
Copy link
Contributor

@jannotti jannotti commented May 26, 2023

Static analysis tools noted that:

for i, sv := range cx.stack {
    stack[i] = stackValueToTealValue(&sv)
}

was a potential problem because sv is always the same variable in a for loop, so this code was passing the same address on each call. That was fine, since stackValueToTealValue is single-threaded, and does not store the address. It's just a simple conversion.

But, noting that the conversion was more complicated than it needed to be, and probably allocated more than it needed to, this PR simplifies it and makes it work on stackValue values instead of pointers.

Also removes the unused function: valueDeltaToValueDelta and associated test.

Test Plan

Existing tests

Static analysis tools noted that:
```
 	for i, sv := range cx.stack {
-		stack[i] = stackValueToTealValue(&sv)
```
was a potential problem because `sv` is always the same variable in a
for loop, so this code was passing the same address on each call.
That was fine, since stackValueToTealValue is single-threaded, and
does not sture the address. It's just a simple conversion.

But, noting that the conversion was more complicated than it needed to
be, and probably allocated more than it needed to, this PR simplifies
it and makes it work on stackValue values instead of pointers.
@jannotti jannotti force-pushed the simplify-debugger-conversion branch from b0a1ab0 to a36c35f Compare May 26, 2023 12:30
@jannotti jannotti self-assigned this May 26, 2023
@codecov
Copy link

codecov bot commented May 26, 2023

Codecov Report

Merging #5421 (cb83b92) into master (e7e76fc) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #5421      +/-   ##
==========================================
+ Coverage   55.32%   55.33%   +0.01%     
==========================================
  Files         452      452              
  Lines       63851    63844       -7     
==========================================
+ Hits        35328    35331       +3     
+ Misses      26094    26086       -8     
+ Partials     2429     2427       -2     
Impacted Files Coverage Δ
data/transactions/logic/debugger.go 69.86% <100.00%> (-1.38%) ⬇️
data/transactions/logic/eval.go 91.27% <100.00%> (ø)

... and 5 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@jannotti jannotti merged commit a10efe5 into algorand:master May 26, 2023
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants