X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=windows%2Fwinmisc.c;h=5bf52141ca7aa1fab834e0d67a559d675cfd481d;hb=a063e522970946bf7d5dc052079d7773c0dee76d;hp=c719c7265e9b77bf1776fa8668dcb59d0ad1bf23;hpb=e5d3a353cc21bd27a103fb4fc147cfc223517c21;p=PuTTY.git diff --git a/windows/winmisc.c b/windows/winmisc.c index c719c726..5bf52141 100644 --- a/windows/winmisc.c +++ b/windows/winmisc.c @@ -5,6 +5,7 @@ #include #include #include "putty.h" +#define SECURITY_WIN32 #include OSVERSIONINFO osVersion; @@ -210,26 +211,23 @@ const char *win_strerror(int error) es = find234(errstrings, &error, errstring_find); if (!es) { - int bufsize; + char msgtext[65536]; /* maximum size for FormatMessage is 64K */ es = snew(struct errstring); es->error = error; - /* maximum size for FormatMessage is 64K */ - bufsize = 65535; - es->text = snewn(bufsize, char); if (!FormatMessage((FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS), NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - es->text, bufsize, NULL)) { - sprintf(es->text, - "Windows error code %d (and FormatMessage returned %d)", - error, GetLastError()); + msgtext, lenof(msgtext)-1, NULL)) { + sprintf(msgtext, + "(unable to format: FormatMessage returned %d)", + GetLastError()); } else { - int len = strlen(es->text); - if (len > 0 && es->text[len-1] == '\n') - es->text[len-1] = '\0'; + int len = strlen(msgtext); + if (len > 0 && msgtext[len-1] == '\n') + msgtext[len-1] = '\0'; } - es->text = sresize(es->text, strlen(es->text) + 1, char); + es->text = dupprintf("Error %d: %s", error, msgtext); add234(errstrings, es); }