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

Fix undefined behaviour in CommandBufferGL.cpp #5694

Merged

Conversation

hexagonrecursion
Copy link
Contributor

By compiling with sanitisers enabled I have detected a number of places where we run into undefined behaviour. The patch for the first is in #5692 (thanks to Web-eWorks). This is a patch for the second issue I detected.

  1. mat->m_pushConstants.get() is sometimes null.
  2. I set a breakpoint in a debugger and it turned out that s->GetConstantStorageSize() == 0
  3. The behaviour of memcpy(dst, src, count) is undefined if either of the pointers is null even if count == zero

Fix: add a null check.

Here is how I compile with sanitisers.
1 Make sure build/ does not exist (because cmake does not update CXXFLAGS for build directories that have already been populated). Alternatively: build in build-with-sanitizers/
2. CXXFLAGS="-fsanitize=address,pointer-compare,pointer-subtract,undefined" LDFLAGS="$CXXFLAGS" cmake -S . -B build/ && make -j2 -C build/

@Web-eWorks
Copy link
Member

Apologies for the delay on reviewing these PRs - thanks for digging into it! I'm always glad to see someone take the time to validate the behavior of the compiled code.

@Web-eWorks Web-eWorks merged commit 45026e5 into pioneerspacesim:master Jan 9, 2024
4 of 5 checks passed
@impaktor
Copy link
Member

impaktor commented Jan 9, 2024

@hexagonrecursion Thanks a bunch for the work you've done! Please let us know if you want to be in AUTHORS.txt, and what to put.

hexagonrecursion added a commit to hexagonrecursion/pioneer that referenced this pull request Apr 2, 2024
pioneerspacesim#5694 (comment) :

> @hexagonrecursion Thanks a bunch for the work you've done! Please let us know if you want to be in [AUTHORS.txt](https://github.com/pioneerspacesim/pioneer/blob/master/AUTHORS.txt), and what to put.
@hexagonrecursion hexagonrecursion deleted the fix-SetupMaterialData branch April 2, 2024 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants