mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-02-06 08:22:01 +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
|
// stupid microsoft makes things complicated
|
||||||
static inline char *get_WSAErrorStr(int e)
|
static inline char *get_WSAErrorStr(int e)
|
||||||
{
|
{
|
||||||
char *buf = NULL;
|
char buf[256]; // allow up to 255 bytes
|
||||||
|
|
||||||
|
buf[0] = '\0';
|
||||||
|
|
||||||
FormatMessageA(
|
FormatMessageA(
|
||||||
FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
|
||||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||||
NULL,
|
NULL,
|
||||||
(DWORD)e,
|
(DWORD)e,
|
||||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||||
(LPTSTR)&buf,
|
(LPTSTR)buf,
|
||||||
0, NULL);
|
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;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue