Fix build against LLVM CFI.

The first line of bssl::New is invalid in LLVM CFI as we are casting a
pointer to T before the object is constructed. Instead, we should leave
it as void* and only use it as a T* afterward being constructed.

Bug: chromium:750445
Change-Id: I0ae60c2a7e541b45bc0155dd8f359b662f561dcc
Reviewed-on: https://boringssl-review.googlesource.com/18684
Commit-Queue: David Benjamin <davidben@google.com>
Commit-Queue: Steven Valdez <svaldez@google.com>
Reviewed-by: Steven Valdez <svaldez@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
David Benjamin 2017-07-31 13:52:31 -04:00 committed by CQ bot account: commit-bot@chromium.org
parent d363247f1e
commit a4cb62f0ae

View File

@ -181,13 +181,12 @@ struct SSL_HANDSHAKE;
* Note: unlike |new|, this does not support non-public constructors. */ * Note: unlike |new|, this does not support non-public constructors. */
template <typename T, typename... Args> template <typename T, typename... Args>
T *New(Args &&... args) { T *New(Args &&... args) {
T *t = reinterpret_cast<T *>(OPENSSL_malloc(sizeof(T))); void *t = OPENSSL_malloc(sizeof(T));
if (t == nullptr) { if (t == nullptr) {
OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
return nullptr; return nullptr;
} }
new (t) T(std::forward<Args>(args)...); return new (t) T(std::forward<Args>(args)...);
return t;
} }
/* Delete behaves like |delete| but uses |OPENSSL_free| to release memory. /* Delete behaves like |delete| but uses |OPENSSL_free| to release memory.