mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-03-07 03:41:25 +00:00
Use temporary buffer with a max size of 255 bytes instead of having Microsoft's FormatMessageA alloc one for us. Also, provide a fallback message in case no message was available for some reason
This commit is contained in:
parent
ec708dcf13
commit
69b7699b2f
1 changed files with 9 additions and 4 deletions
13
src/i_tcp.c
13
src/i_tcp.c
|
|
@ -266,17 +266,22 @@ static void wattcp_outch(char s)
|
|||
// stupid microsoft makes things complicated
|
||||
static inline char *get_WSAErrorStr(int e)
|
||||
{
|
||||
char *buf = NULL;
|
||||
char buf[256]; // allow up to 255 bytes
|
||||
|
||||
buf[0] = '\0';
|
||||
|
||||
FormatMessageA(
|
||||
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL,
|
||||
(DWORD)e,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
(LPTSTR)&buf,
|
||||
0, NULL);
|
||||
(LPTSTR)buf,
|
||||
sizeof (buf),
|
||||
NULL);
|
||||
|
||||
if (!buf[0]) // provide a fallback error message if no message is available for some reason
|
||||
sprintf(buf, "Unknown error");
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue