GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — zlib: fix pointer alignment · nodejs/node@17965eb

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src
    • node_zlib.cc
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/node_zlib.cc‎

Copy file name to clipboardExpand all lines: src/node_zlib.cc
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,8 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
608608
}
609609

610610
static void* AllocForBrotli(void* data, size_t size) {
611-
size += sizeof(size_t);
611+
constexpr size_t offset = std::max(sizeof(size_t), alignof(max_align_t));
612+
size += offset;
612613
CompressionStream* ctx = static_cast<CompressionStream*>(data);
613614
char* memory = UncheckedMalloc(size);
614615
if (memory == nullptr) [[unlikely]] {
@@ -617,15 +618,16 @@ class CompressionStream : public AsyncWrap, public ThreadPoolWork {
617618
*reinterpret_cast<size_t*>(memory) = size;
618619
ctx->unreported_allocations_.fetch_add(size,
619620
std::memory_order_relaxed);
620-
return memory + sizeof(size_t);
621+
return memory + offset;
621622
}
622623

623624
static void FreeForZlib(void* data, void* pointer) {
624625
if (pointer == nullptr) [[unlikely]] {
625626
return;
626627
}
627628
CompressionStream* ctx = static_cast<CompressionStream*>(data);
628-
char* real_pointer = static_cast<char*>(pointer) - sizeof(size_t);
629+
constexpr size_t offset = std::max(sizeof(size_t), alignof(max_align_t));
630+
char* real_pointer = static_cast<char*>(pointer) - offset;
629631
size_t real_size = *reinterpret_cast<size_t*>(real_pointer);
630632
ctx->unreported_allocations_.fetch_sub(real_size,
631633
std::memory_order_relaxed);

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.