mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-01-17 23:21:22 +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
3b39a25ade
commit
e4e76f83c3
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…
Reference in a new issue