Re: [hyperdex-discuss] about treadstone_transformer structure in libtreadstone

19 views
Skip to first unread message

Robert Escriva

unread,
Feb 5, 2016, 9:19:20 AM2/5/16
to hyperdex...@googlegroups.com, 李俊良
Memmove only happens when it's non null. There's a comparison to null, but not an assignment. The only way it can be null is from malloc which implies size is zero and there's nothing to copy, or malloc failed. On Linux the oom killer kicks in instead of malloc failing.

On February 5, 2016 3:51:05 AM EST, "李俊良" <cna...@gmail.com> wrote:
>i found a problem in treadstone.cc of file, if NULL assign m_binary,
>how to
>perform a function memmove?
>
>treadstone_transformer :: treadstone_transformer(const unsigned char*
>binary
>, size_t binary_sz)
> : m_binary()
> , m_binary_sz()
> , m_binary_cap()
> , m_error(false)
>{
>m_binary = reinterpret_cast<unsigned char*>(malloc(sizeof(unsigned char
>*) * binary_sz));
> m_binary_sz = binary_sz;
> m_binary_cap = binary_sz;
> m_error = m_binary == NULL;
>
> if (m_binary)
> {
> memmove(m_binary, binary, binary_sz);
> }
>}

--
Sent from my phone. Please excuse my brevity.

Robert Escriva

unread,
Feb 5, 2016, 9:20:42 AM2/5/16
to hyperdex...@googlegroups.com, 李俊良
Looking at the code again, if malloc fails, error is set, so there's no assumption about being on Linux in its default configuration.
Reply all
Reply to author
Forward
0 new messages