Skip to content

0.2.0: fix heap corruption, configurable alignment, Unity tests, GitHub Actions - #5

Merged
tomdionysus merged 6 commits into
mainfrom
feature/fixes-ci-docs
Nov 12, 2026
Merged

tomdionysus merged 6 commits into
mainfrom
feature/fixes-ci-docs

Conversation

@tomdionysus

Copy link
Copy Markdown
Owner

No function, type or declaration changes: code written against the current release compiles and links unchanged, and the old examples build and run against this branch.

Fixes

  • Allocating into a hole between blocks cut the assigned chain short, which could lead realloc to treat a live block as free.
  • Splitting a free block whose remainder was smaller than a header wrapped freemem to about 4 GiB.
  • Chain inserts could leave stale links on the inserted block.
  • Growing with realloc could read past the end of a region, or write a free header over the next block.
  • pmalloc_addblock added the running free total to totalmem, so it was wrong after a second region; it also accepted NULL and unusably small regions.
  • pmalloc_calloc did not check num * size for overflow, and sizes near 4 GiB wrapped when aligned.
  • The suballocation example copied a string into a block one byte too small.

Changes

  • Alignment is PMALLOC_ALIGN (compile-time or CMake option), defaulting to the pointer size as before. Headers are padded to it, and invalid values fail to compile.
  • pmalloc_sizeof reports the requested size again instead of the rounded size. A block that kept a remainder too small to become a free block reports its whole usable size.
  • Regions that touch existing memory are kept PMALLOC_ALIGN bytes apart, so they are never merged and the accounting holds.
  • PMALLOC_VERSION macros (0.2.0), extern "C" guards, and a CMake pmalloc::pmalloc package with install rules.

Tests and CI

  • Tests are rewritten in C on a vendored Unity 2.7.0: 55 tests, a heap invariant checker and seeded stress runs, with 100% line and branch coverage of pmalloc.c. They pass on macOS and Linux, GCC and Clang, 32-bit and 64-bit, alignments 8 to 64, and under ASan and UBSan.
  • CircleCI is replaced by GitHub Actions: a build matrix, a Cortex-M0/M4 cross-compile, coverage gated at 100% and uploaded to Codecov, and CodeQL.

Docs

The README is now a getting-started guide with badges. The API reference moves to docs/API.md, and CHANGELOG.md records this release.

Allocating into a hole cut the assigned chain short, a split remainder
smaller than a header wrapped freemem, chain inserts left stale links,
realloc could grow past the end of a region or over the next block's
header, addblock miscounted totalmem across regions, and calloc and the
alignment rounding could overflow.

Alignment is now PMALLOC_ALIGN, defaulting to the pointer size, with
headers padded to it. pmalloc_sizeof reports the requested size again.
No declaration or type changes. Adds PMALLOC_VERSION 0.2.0.
The tests are rewritten in C against a vendored Unity 2.7.0, so the
project is C only and nothing is downloaded. 55 tests cover every line
and branch of pmalloc.c, with a heap invariant checker and seeded
stress runs.

CMake reads the version from pmalloc.h, scopes warnings to pmalloc's
own targets, adds PMALLOC_* options, and installs a pmalloc::pmalloc
package. Tests and examples build only at top level.
CI builds and tests on Linux GCC and Clang, 32-bit, several alignments
and macOS, cross-compiles for Cortex-M0 and M4, and requires 100% line
and branch coverage before uploading to Codecov.
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

@codecov-commenter

Copy link
Copy Markdown

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

Thanks for integrating Codecov - We've got you covered ☂️

@tomdionysus
tomdionysus merged commit 6b1ac42 into main Nov 12, 2026
11 checks passed
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.

3 participants