Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
S
ScalFMM
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 5
    • Issues 5
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Operations
    • Operations
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
  • solverstack
  • ScalFMM
  • Issues
  • #23

Closed
Open
Opened Nov 20, 2019 by Ghost User@ghost

Undefined behavior in call to memcpy

The file Src/Components/FBasicParticleContainer.hpp contains two calls to memcpy(), where the second parameter (the source pointer) can be null. This only happens when the third parameter (the byte count) is zero. This is, however, undefined behavior. According to cppreference.com:

If either dest or src is a null pointer, the behavior is undefined, even if count is zero.

(emphasis mine).

Affected versions: I only tested the version tagged "V1.5.1".

Test: The script

CXX_FLAGS="-std=c++14 -fsanitize=undefined"
cd Tests/Utils/
rm -f testOctreeRearrange
g++ $CXX_FLAGS testOctreeRearrange.cpp -o testOctreeRearrange
./testOctreeRearrange

displays these error messages:

../../Src/Components/FBasicParticleContainer.hpp:117:23: runtime error: null pointer passed as argument 2, which is declared to never be null
../../Src/Components/FBasicParticleContainer.hpp:126:23: runtime error: null pointer passed as argument 2, which is declared to never be null

Solution: Only memcpy if nbParticles is non zero:

sed -i 's/memcpy/if (nbParticles != 0) memcpy/' Src/Components/FBasicParticleContainer.hpp
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: solverstack/ScalFMM#23