Skip to content
Permalink
Browse files

src: replace c-style cast

PR-URL: #26888
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Signed-off-by: Beth Griggs <Bethany.Griggs@uk.ibm.com>
  • Loading branch information...
gengjiawen authored and BethGriggs committed Mar 24, 2019
1 parent 1b2a078 commit aa6a74110266c44045534b6b9e8bb35cd56d1080
Showing with 12 additions and 6 deletions.
  1. +12 −6 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<LPTSTR>(&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<Value> WinapiErrnoException(Isolate* isolate,
int errorno,
const char* syscall,
@@ -231,8 +236,9 @@ Local<Value> WinapiErrnoException(Isolate* isolate,
.FromJust();
}

if (must_free)
LocalFree((HLOCAL)msg);
if (must_free) {
LocalFree(const_cast<char*>(msg));
}

return e;
}

0 comments on commit aa6a741

Please sign in to comment.
You can’t perform that action at this time.