neo
neo copied to clipboard
`[Fix]` unalignment memory load in Neo.VM Unsafe.NotZero(ReadOnlySpan<byte>) and remove the use of `unsafe`
Description
The Unsafe.NotZero(ReadOnlySpan<byte>) method in Neo.VM use long* to load data from ReadOnlySpan<byte> for better performance, but this approach may result in misaligned memory access. This approach is no problem on x86 CPUs, but it may cause bug on some RISC CPUs(for example, some ARM CPUs).
Fixes # (issue)
Type of change
- [ ] Optimization (the change is only an optimization)
- [ ] Style (the change is only a code style for better maintenance or standard purpose)
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update
Test Configuration:
Checklist:
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules
netstandard2.1 problems
Fix to make compatible with
netstandard2.1. And MoveNotZeromethod toNeo.Extensionslibrary.Error: /Users/runner/work/neo/neo/src/Neo.VM/Utility.cs(38,22): error CS1061: 'ReadOnlySpan<byte>' does not contain a definition for 'IndexOfAnyExcept' and no accessible extension method 'IndexOfAnyExcept' accepting a first argument of type 'ReadOnlySpan<byte>' could be found (are you missing a using directive or an assembly reference?) [/Users/runner/work/neo/neo/src/Neo.VM/Neo.VM.csproj::TargetFramework=netstandard2.1]
🥲