From f049edbf1204b552d59164089374fd530eada939 Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Tue, 31 Jan 2023 14:32:56 +0100 Subject: [PATCH 1/3] Use parenthesis for alloc_assert macro --- src/err.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/err.hpp b/src/err.hpp index 3f3278f8..c283e6a5 100644 --- a/src/err.hpp +++ b/src/err.hpp @@ -172,7 +172,7 @@ int wsa_error_to_errno (int errcode_); // Provides convenient way to check whether memory allocation have succeeded. #define alloc_assert(x) \ do { \ - if (unlikely (!x)) { \ + if (unlikely (!(x))) { \ fprintf (stderr, "FATAL ERROR: OUT OF MEMORY (%s:%d)\n", __FILE__, \ __LINE__); \ fflush (stderr); \ From d16db180d37a346c1dfa8019eed3c9e79e760522 Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Tue, 31 Jan 2023 14:36:56 +0100 Subject: [PATCH 2/3] Do not break if malloc size is zero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I get a scenario where `size_` is `0` so there is nothing to `malloc()`. According to `malloc(3)`: If size is 0, then malloc() returns either NULL, or a unique pointer value thatcan later be success‐fully passed to free(). According to `free(3)`: If ptr is NULL, no operation is performed. So, if `size_` is null and `_data` also, there is no OOM error. We can adjust the assert to not fail on this scenario. --- src/blob.hpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/blob.hpp b/src/blob.hpp index 06a41913..d84bba64 100644 --- a/src/blob.hpp +++ b/src/blob.hpp @@ -81,7 +81,7 @@ struct blob_t _size (size_), _owned (true) { - alloc_assert (_data); + alloc_assert (!_size || _data); } // Creates a blob_t of a given size, an initializes content by copying @@ -91,8 +91,10 @@ struct blob_t _size (size_), _owned (true) { - alloc_assert (_data); - memcpy (_data, data_, size_); + alloc_assert (!size_ || _data); + if (size_ && _data) { + memcpy (_data, data_, size_); + } } // Creates a blob_t for temporary use that only references a @@ -126,10 +128,12 @@ struct blob_t { clear (); _data = static_cast (malloc (other_._size)); - alloc_assert (_data); + alloc_assert (!other_._size || _data); _size = other_._size; _owned = true; - memcpy (_data, other_._data, _size); + if (_size && _data) { + memcpy (_data, other_._data, _size); + } } // Sets a blob_t to a copy of a given buffer. @@ -137,10 +141,12 @@ struct blob_t { clear (); _data = static_cast (malloc (size_)); - alloc_assert (_data); + alloc_assert (!size_ || _data); _size = size_; _owned = true; - memcpy (_data, data_, size_); + if (size_ && _data) { + memcpy (_data, data_, size_); + } } // Empties a blob_t. From 52333da0e2a52f2ba2ab9132124f98c71a49317e Mon Sep 17 00:00:00 2001 From: Marco Casaroli Date: Thu, 2 Feb 2023 09:03:18 +0100 Subject: [PATCH 3/3] Add RELICENSE for Marco Casaroli --- RELICENSE/casaroli.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 RELICENSE/casaroli.md diff --git a/RELICENSE/casaroli.md b/RELICENSE/casaroli.md new file mode 100644 index 00000000..97ea9285 --- /dev/null +++ b/RELICENSE/casaroli.md @@ -0,0 +1,16 @@ +# Permission to Relicense under MPLv2 or any other OSI approved license chosen by the current ZeroMQ BDFL + +This is a statement by Marco Casaroli that grants permission to +relicense its copyrights in the libzmq C++ library (ZeroMQ) under the +Mozilla Public License v2 (MPLv2) or any other Open Source Initiative +approved license chosen by the current ZeroMQ BDFL (Benevolent +Dictator for Life). + +A portion of the commits made by the Github handle "casaroli", with +commit author "Marco Casaroli ", are +copyright of Marco Casaroli. This document hereby grants the libzmq +project team to relicense libzmq, including all past, present and +future contributions of the author listed above. + +Marco Casaroli +2023/2/2