Commits

Armin Rigo  committed 7ce0a6e

Like CPython, strip the message from trailing dots.

  • Participants
  • Parent commits f262c7a
  • Branches release-2.2.x

Comments (0)

Files changed (1)

File rpython/rlib/rwin32.py

     def llimpl_FormatError(code):
         "Return a message corresponding to the given Windows error code."
         buf = lltype.malloc(rffi.CCHARPP.TO, 1, flavor='raw')
-
+        buf[0] = lltype.nullptr(rffi.CCHARP.TO)
         try:
             msglen = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
                                    FORMAT_MESSAGE_FROM_SYSTEM,
                                    DEFAULT_LANGUAGE,
                                    rffi.cast(rffi.CCHARP, buf),
                                    0, None)
+            buflen = intmask(msglen)
 
-            if msglen <= 2:   # includes the case msglen < 0
-                return fake_FormatError(code)
+            # remove trailing cr/lf and dots
+            s_buf = buf[0]
+            while buflen > 0 and (s_buf[buflen - 1] <= ' ' or
+                                  s_buf[buflen - 1] == '.'):
+                buflen -= 1
 
-            # FormatMessage always appends \r\n.
-            buflen = intmask(msglen - 2)
-            assert buflen > 0
-
-            result = rffi.charpsize2str(buf[0], buflen)
+            if buflen <= 0:
+                result = fake_FormatError(code)
+            else:
+                result = rffi.charpsize2str(s_buf, buflen)
+        finally:
             LocalFree(rffi.cast(rffi.VOIDP, buf[0]))
-        finally:
             lltype.free(buf, flavor='raw')
 
         return result