mirror of
https://github.com/zeromq/libzmq.git
synced 2024-12-12 10:33:52 +01:00
Merge pull request #4502 from casaroli/fix-for-nuttx
Fixes for memory allocation and zero size
This commit is contained in:
commit
6e2d632b18
16
RELICENSE/casaroli.md
Normal file
16
RELICENSE/casaroli.md
Normal file
@ -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 <marco.casaroli@gmail.com>", 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
|
20
src/blob.hpp
20
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<unsigned char *> (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<unsigned char *> (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.
|
||||
|
@ -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); \
|
||||
|
Loading…
Reference in New Issue
Block a user