From 4d2739453d96310efe257e02d02127a7a71122f4 Mon Sep 17 00:00:00 2001 From: gengjiawen Date: Sun, 24 Mar 2019 08:29:51 -0400 Subject: [PATCH] src: replace c-style cast PR-URL: https://github.com/nodejs/node/pull/26888 Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater Reviewed-By: Refael Ackermann Reviewed-By: Anna Henningsen --- src/api/exceptions.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/api/exceptions.cc b/src/api/exceptions.cc index 74987c2673bd33..1025991063e710 100644 --- a/src/api/exceptions.cc +++ b/src/api/exceptions.cc @@ -162,15 +162,21 @@ static const char* winapi_strerror(const int errorno, bool* must_free) { char* errmsg = nullptr; FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, errorno, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&errmsg, 0, nullptr); + FORMAT_MESSAGE_IGNORE_INSERTS, + nullptr, + errorno, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + reinterpret_cast(&errmsg), + 0, + nullptr); if (errmsg) { *must_free = true; // Remove trailing newlines for (int i = strlen(errmsg) - 1; - i >= 0 && (errmsg[i] == '\n' || errmsg[i] == '\r'); i--) { + i >= 0 && (errmsg[i] == '\n' || errmsg[i] == '\r'); + i--) { errmsg[i] = '\0'; } @@ -182,7 +188,6 @@ static const char* winapi_strerror(const int errorno, bool* must_free) { } } - Local WinapiErrnoException(Isolate* isolate, int errorno, const char* syscall, @@ -231,8 +236,9 @@ Local WinapiErrnoException(Isolate* isolate, .FromJust(); } - if (must_free) - LocalFree((HLOCAL)msg); + if (must_free) { + LocalFree(const_cast(msg)); + } return e; }