]> git.eshelyaron.com Git - emacs.git/commitdiff
Improved format string error message (bug#58168)
authorMattias Engdegård <mattiase@acm.org>
Fri, 7 Oct 2022 16:17:40 +0000 (18:17 +0200)
committerMattias Engdegård <mattiase@acm.org>
Sat, 8 Oct 2022 16:48:30 +0000 (18:48 +0200)
* src/editfns.c (styled_format): Better message when the conversion
char is non-ASCII from a unibyte format string.

src/editfns.c

index c1414071c790f9695d325ad05584b358bf36ee41..3f9618edb087a82913ca221870ef1a7b8154131a 100644 (file)
@@ -3551,10 +3551,15 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message)
                      || float_conversion || conversion == 'i'
                      || conversion == 'o' || conversion == 'x'
                      || conversion == 'X'))
-           error ("Invalid format operation %%%c",
-                  multibyte_format
-                  ? STRING_CHAR ((unsigned char *) format - 1)
-                  : *((unsigned char *) format - 1));
+           {
+             unsigned char *p = (unsigned char *) format - 1;
+             if (multibyte_format)
+               error ("Invalid format operation %%%c", STRING_CHAR (p));
+             else
+               error (*p <= 127 ? "Invalid format operation %%%c"
+                                : "Invalid format operation char #o%03o",
+                      *p);
+           }
          else if (! (FIXNUMP (arg) || ((BIGNUMP (arg) || FLOATP (arg))
                                        && conversion != 'c')))
            error ("Format specifier doesn't match argument type");