Skip to content

Commit

Permalink
src: replace c-style cast
Browse files Browse the repository at this point in the history
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 Apr 9, 2019
1 parent 1b2a078 commit aa6a741
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/api/exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand All @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit aa6a741

Please sign in to comment.