From 75283ccdb3183a6461281959ce372d258568cec3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jerry=20Lundstr=C3=B6m?= Date: Wed, 16 Aug 2023 11:30:36 +0200 Subject: [PATCH] Doc - `README`: Mention PowerTools for libpcap-devel - `RefCountString`: Use anonymous array for `data` --- README.md | 2 +- src/refcountstring.h | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0de7f5f..a8c29e5 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ To install the dependencies under Debian/Ubuntu: apt-get install -y zlib1g-dev libmaxminddb-dev ``` -To install the dependencies under CentOS (with EPEL enabled): +To install the dependencies under CentOS (with EPEL/PowerTools enabled): ``` yum install -y zlib-devel libmaxminddb-devel ``` diff --git a/src/refcountstring.h b/src/refcountstring.h index 2a80024..193385e 100644 --- a/src/refcountstring.h +++ b/src/refcountstring.h @@ -33,7 +33,7 @@ struct RefCountString { // data int count; - char data[sizeof(int)]; // this is a dummy, actual array will be larger + char data[]; // implementation void inc_refcount() @@ -50,9 +50,7 @@ struct RefCountString { static RefCountString* allocate(int data_length) { - std::size_t size = sizeof(RefCountString) - sizeof(char[sizeof(int)]) + data_length * sizeof(char); - - void* chunk = std::calloc(1, size); + void* chunk = std::calloc(1, sizeof(RefCountString) + data_length); if (!chunk) throw std::bad_alloc();