diff --git a/modules/libcom/src/osi/os/WIN32/osdFindSymbol.c b/modules/libcom/src/osi/os/WIN32/osdFindSymbol.c index 2753f0959..6c1fb401c 100644 --- a/modules/libcom/src/osi/os/WIN32/osdFindSymbol.c +++ b/modules/libcom/src/osi/os/WIN32/osdFindSymbol.c @@ -51,19 +51,27 @@ epicsShareFunc const char *epicsLoadError(void) DWORD n; n = FormatMessage( - FORMAT_MESSAGE_FROM_SYSTEM, + FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, epicsLoadErrorCode, 0, buffer, sizeof(buffer)-1, NULL ); - /* n - number of chars stored excluding nil. - * - * Some messages include a trailing newline, which we strip. - */ - for(; n>=1 && (buffer[n-1]=='\n' || buffer[n-1]=='\r'); n--) - buffer[n-1] = '\0'; + if(n) { + /* n - number of chars stored excluding nil. + * + * Some messages include a trailing newline, which we strip. + */ + for(; n>=1 && (buffer[n-1]=='\n' || buffer[n-1]=='\r'); n--) + buffer[n-1] = '\0'; + } else { + epicsSnprintf(buffer, sizeof(buffer), + "Unable to format WIN32 error code %lu", + (unsigned long)epicsLoadErrorCode); + buffer[sizeof(buffer)-1] = '\0'; + + } return buffer; }