Skip to content

Commit

Permalink
Save two redundant calls of GetLastError() (#589)
Browse files Browse the repository at this point in the history
Assuming there was an eror during printing (wvsprintf) inside of vprintLastError(), the second call could have returned a different error code than expected.

Apart from that, to me it looks to be an idiom to call GetLastError() only once per error. In every case, printing errors now should be a tiny little bit faster. :-)
  • Loading branch information
LinqLover authored Dec 5, 2024
1 parent 9d41521 commit bd442a2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions platforms/win32/vm/sqWin32Utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void printLastError(TCHAR *prefix)

lastError = GetLastError();
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
NULL, lastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf, 0, NULL );
warnPrintfT(TEXT("%s (%ld) -- %s\n"), prefix, lastError, (LPTSTR)lpMsgBuf);
LocalFree( lpMsgBuf );
Expand All @@ -151,7 +151,7 @@ void vprintLastError(TCHAR *fmt, ...)
va_end(args);

FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
NULL, lastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf, 0, NULL );
len = (int)_tcslen(lpMsgBuf);
// nuke any cr-lf or lf at the end of the string...
Expand Down

0 comments on commit bd442a2

Please sign in to comment.