Skip to content

[email protected] - Resolves memory overflow warnings#20474

Open
cabelo wants to merge 2 commits intoggml-org:masterfrom
cabelo:warning_repack
Open

[email protected] - Resolves memory overflow warnings#20474
cabelo wants to merge 2 commits intoggml-org:masterfrom
cabelo:warning_repack

Conversation

@cabelo
Copy link
Contributor

@cabelo cabelo commented Mar 13, 2026

Make sure to read the contributing guidelines before submitting a PR

fix(repack): resolves memory overflow warnings and declaration error in make_block_*

  • Fixes multiple warning: writing 32 bytes into a region of size 0 [-Wstringop-overflow=]
    in make_block_q4_0x4, make_block_q4_0x8, etc., caused by the use of memcpy in
    dynamically calculated offsets, which confuses static analysis in GCC 13+.

  • Adds explicit bounds checking (if + GGML_ASSERT) before each memcpy,
    ensuring that src_offset and dst_offset do not exceed the sizes of the arrays
    (qs[]) within the blocks.

  • Replaces memcpy directly with std::memcpy (C++) to avoid aliasing problems and
    improve compatibility with compiler optimizations. - Adds static_assert to validate block sizes (block_q4_0x4::qs == 64,

block_q4_Kx8::qs == 1024, etc.), preventing future errors if QK_* changes.

  • Fixes compilation error make_block_q4_0x4 was not declared in this scope by declaring all auxiliary functions make_block_* as static at the top of the repack.cpp file, before extern "C", following good C++ practices (internal binding).

  • No changes to algorithm logic — only memory safety and compatibility with modern compilers (GCC ≥13, Clang ≥14).

Before:

image

After

ok

@cabelo cabelo requested a review from ggerganov as a code owner March 13, 2026 02:48
@github-actions github-actions bot added the ggml changes relating to the ggml tensor library for machine learning label Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant