Skip to content

Blog: Modern Memory Safe C++?#2501

Open
bartlettroscoe wants to merge 15 commits intomainfrom
252-cpp-memory-safety-blog
Open

Blog: Modern Memory Safe C++?#2501
bartlettroscoe wants to merge 15 commits intomainfrom
252-cpp-memory-safety-blog

Conversation

@bartlettroscoe
Copy link
Copy Markdown
Member

Description

EB Member: @bernhold

Resolves Blog planning #252

PR checklist for files displayed on bssw.io site

  • [Author] @mention the BSSw.io editorial board member @<eb-member-id> in Description above assigned to shepherd your PR.
  • [Author] Add the <issue-id> in the Description above for the associated GitHub Issue.
  • [Author] ensure the submission uses one sentence per line.
  • [Author] Ensure wikize_refs.py -i <base>.md is run and commit (if using wikize_refs.py).
  • [Author] Inspect the content in the *.md file(s) as rendered in GitHub for this PR.
  • [EB Mem] Assign this PR to the EB member <eb-member-id>.
  • [EB Mem] Assign this PR to the author of the PR <pr-author-id>.
  • [EB Mem] Add one or more Reviewers.
  • [EB Mem] Add label content: <content-type> for the type of contribution.
  • [EB Mem] Add to Project Content Development (see Content Development).
  • [EB Mem] Add meta-data to the *.md file(s) (set Publish: yes).
  • [EB Mem] Add label preview (so PR branch will be merged to 'preview' branch and watch for possible merge failures).
  • [EB Mem] Rebuild preview site and confirm new content is there, renders correctly and is returned in searches.
  • [Author] Make any final changes to the PR based on feedback.
  • [ ] [Author] Ensure wikize_refs.py -i <base>.md is run and commit (if using wikize_refs.py).
  • [EB Mem] Rebuild preview site and re-confirm content looks correct.
  • [EB Mem] Ensure at least one reviewer signs off on the final changes.
  • [EB Mem] Move the PR to "Ready to Publish" in Content Development.
  • [EB Mem] Leave comment and @mention @betterscientificsoftware/bssw-maint (BSSw Maint) asking to carry out final publication steps.
  • [BSSw Maint] Verify that all needed files are present in the PR (article, images, updates to Site/Homepage.md carousel and/or Site/Announcements/Announcements.md as appropriate).
  • [BSSw Maint] Merge PR. (Should automatically move to "Done" in Content Development.)
  • [BSSw Maint] Verify new contribution shows up on bssw.io as expected.

NOTE:

  • Checklist items prefixed with [Author] are expected to be performed by the author of the PR or can be performed by the author.
  • Checklist items prefixed with [EB Mem] must be performed by a BSSw.io Editorial Board (EB) Member.
  • Checklist items prefixed with [BSSw Maint] must be performed by someone in the @betterscientificsoftware/bssw-maint team (hint: type @, b, s, s, w, -, m to auto-complete to @betterscientificsoftware/bssw-maint).

@bartlettroscoe bartlettroscoe requested a review from bernhold March 24, 2026 11:31
@bartlettroscoe bartlettroscoe added content: blog For blog content preview Merge PR to the 'preview' branch to allow display on preview.bssw.io labels Mar 24, 2026
@github-project-automation github-project-automation bot moved this to Idea backlog in Content Development Mar 24, 2026
Comment on lines +16 to +17
Of the CWE Top 25 Most Dangerous Software Weaknesses in 2025,<sup>[1]</sup> six are directly related to memory access errors in unsafe languages like C++: out-of-bounds write (5), use after free (7), out-of-bounds read (8), buffer copy without checking size of input (11), null pointer dereference (13), and stack-based buffer overflow (14).
(However, note that this is a significant reduction from the 2023 list, where memory errors occupied the top three spots: use after free (1), heap-based buffer overflow (2), and out-of-bounds write (3).<sup>[2]</sup>)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these might be more readable as a lists, with a clearer indication that the number is the ranking, not a count. Something like "#5" or "5th".


Of the CWE Top 25 Most Dangerous Software Weaknesses in 2025,<sup>[1]</sup> six are directly related to memory access errors in unsafe languages like C++: out-of-bounds write (5), use after free (7), out-of-bounds read (8), buffer copy without checking size of input (11), null pointer dereference (13), and stack-based buffer overflow (14).
(However, note that this is a significant reduction from the 2023 list, where memory errors occupied the top three spots: use after free (1), heap-based buffer overflow (2), and out-of-bounds write (3).<sup>[2]</sup>)
So while memory safety issues did not dominate the reported memory vulnerabilities in 2025, memory-safety bugs remain one of the most persistent sources of serious software defects and security vulnerabilities.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it "memory safety" or "memory-safety"? Just be consistent, either way.

The C++ standards work suggests how the remaining major categories could be addressed more systematically.
A future profiles framework could combine a `std::bounds` profile to inject bounds checks, a `std::lifetime` profile to reject manual `delete` and `free` and to check for null dereference, and a `std::initialization` profile to verify that objects are initialized before use.<sup>[11],[12],[13]</sup>
That same direction could then be extended with a `std::type` profile to restrict unsafe casts and wrong-type access, plus an invalidation profile to prevent use of iterators, pointers, references, and views after a container mutation or destruction.<sup>[14],[17]</sup>
Together with custom `clang-tidy` checks that discourage persistent raw C++ references, uture LLVM lifetime and invalidation analysis, and other rule checks, this can create a subset of C++ that could come reasonably close to being memory safe in practice for most HPC C++ programs, while still maintaining near maximum performance.<sup>[5],[6],[11]</sup>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Together with custom `clang-tidy` checks that discourage persistent raw C++ references, uture LLVM lifetime and invalidation analysis, and other rule checks, this can create a subset of C++ that could come reasonably close to being memory safe in practice for most HPC C++ programs, while still maintaining near maximum performance.<sup>[5],[6],[11]</sup>
Together with custom `clang-tidy` checks that discourage persistent raw C++ references, future LLVM lifetime and invalidation analysis, and other rule checks, this can create a subset of C++ that could come reasonably close to being memory safe in practice for most HPC C++ programs, while still maintaining near maximum performance.<sup>[5],[6],[11]</sup>

Copy link
Copy Markdown
Contributor

@ksbeattie ksbeattie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of minor, easy to fix changes suggested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

content: blog For blog content preview Merge PR to the 'preview' branch to allow display on preview.bssw.io

Projects

Status: Idea backlog

Development

Successfully merging this pull request may close these issues.

3 participants