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>
diff --git a/ssl/internal.h b/ssl/internal.h index c8a96a4..fdd3cb5 100644 --- a/ssl/internal.h +++ b/ssl/internal.h
@@ -181,13 +181,12 @@ * Note: unlike |new|, this does not support non-public constructors. */ template <typename T, typename... Args> T *New(Args &&... args) { - T *t = reinterpret_cast<T *>(OPENSSL_malloc(sizeof(T))); + void *t = OPENSSL_malloc(sizeof(T)); if (t == nullptr) { OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE); return nullptr; } - new (t) T(std::forward<Args>(args)...); - return t; + return new (t) T(std::forward<Args>(args)...); } /* Delete behaves like |delete| but uses |OPENSSL_free| to release memory.