]> git.eshelyaron.com Git - emacs.git/commitdiff
Parse XBM images which use character escapes for hex literals
authorPo Lu <luangruo@yahoo.com>
Fri, 18 Feb 2022 01:12:48 +0000 (09:12 +0800)
committerPo Lu <luangruo@yahoo.com>
Fri, 18 Feb 2022 01:12:48 +0000 (09:12 +0800)
* src/image.c (xbm_scan): Implement parsing of hex escapes in
character literals.

src/image.c

index 5c1bf8d7be673d167b72dc52b755f27b98192e59..d012fcea6a787e1cba3b5bca8dc2c330d78e7c62 100644 (file)
@@ -3681,6 +3681,48 @@ xbm_scan (char **s, char *end, char *sval, int *ival)
       *ival = value;
       return overflow ? XBM_TK_OVERFLOW : XBM_TK_NUMBER;
     }
+  /* Character literal.  XBM images typically contain hex escape
+     sequences and not actual characters, so we only try to handle
+     that here.  */
+  else if (c == '\'')
+    {
+      int value = 0, digit;
+      bool overflow = false;
+
+      if (*s == end)
+       return 0;
+
+      c = *(*s)++;
+
+      if (c != '\\' || *s == end)
+       return 0;
+
+      c = *(*s)++;
+
+      if (c == 'x')
+       {
+         while (*s < end)
+           {
+             c = *(*s)++;
+
+             if (c == '\'')
+               {
+                 *ival = value;
+                 return overflow ? XBM_TK_OVERFLOW : XBM_TK_NUMBER;
+               }
+
+             digit = char_hexdigit (c);
+
+             if (digit < 0)
+               return 0;
+
+             overflow |= INT_MULTIPLY_WRAPV (value, 16, &value);
+             value += digit;
+           }
+
+         return 0;
+       }
+    }
   else if (c_isalpha (c) || c == '_')
     {
       *sval++ = c;