[uim-commit] r2331 - branches/r5rs/sigscheme

yamaken at freedesktop.org yamaken at freedesktop.org
Sat Dec 3 11:13:14 PST 2005


Author: yamaken
Date: 2005-12-03 11:13:07 -0800 (Sat, 03 Dec 2005)
New Revision: 2331

Modified:
   branches/r5rs/sigscheme/read.c
Log:
* sigscheme/read.c
  - (TOKEN_BUF_EXCEEDED): New macro
  - (read_token): Support partial read
  - (read_char, read_number_or_symbol, read_number): Follow the new
    interface of read_token() and generate more specific error message


Modified: branches/r5rs/sigscheme/read.c
===================================================================
--- branches/r5rs/sigscheme/read.c	2005-12-03 18:55:30 UTC (rev 2330)
+++ branches/r5rs/sigscheme/read.c	2005-12-03 19:13:07 UTC (rev 2331)
@@ -73,6 +73,8 @@
 /*=======================================
   File Local Macro Declarations
 =======================================*/
+#define TOKEN_BUF_EXCEEDED (~0UL)
+
 #define MB_MAX_SIZE (SCM_MB_MAX_LEN + sizeof((char)'\0'))
 
 /* can accept "backspace" of R5RS and "U0010FFFF" of SRFI-75 */
@@ -427,6 +429,9 @@
 
     buf[0] = c;
     len = read_token(port, &buf[1], sizeof(buf) - 1, DELIMITER_CHARS);
+    if (len == TOKEN_BUF_EXCEEDED)
+        ERR("invalid character literal");
+
     CDBG((SCM_DBG_PARSER, "read_char : ch = %s", buf));
 
 #if SCM_USE_SRFI75
@@ -537,6 +542,7 @@
 {
     int c, str_len;
     char *str = NULL;
+    size_t len;
     char buf[INT_LITERAL_LEN_MAX + sizeof((char)'\0')];
 
     CDBG((SCM_DBG_PARSER, "read_number_or_symbol"));
@@ -548,7 +554,9 @@
             return read_number(port, 'd');
 
         if (c == '+' || c == '-') {
-            read_token(port, buf, sizeof(buf), DELIMITER_CHARS);
+            len = read_token(port, buf, sizeof(buf), DELIMITER_CHARS);
+            if (len == TOKEN_BUF_EXCEEDED)
+                ERR("invalid number literal");
             if (!buf[1])
                 return Scm_Intern(buf);
             return parse_number(port, buf, sizeof(buf), 'd');
@@ -631,6 +639,8 @@
             *p++ = c;
         } else {
 #if SCM_USE_SRFI75
+            if (&buf[buf_size] <= p + SCM_MB_MAX_LEN)
+                break;
             /* FIXME: check Unicode capability of Scm_current_char_codec */
             p = SCM_CHARCODEC_INT2STR(Scm_current_char_codec,
                                       p, c, SCM_MB_STATELESS);
@@ -639,7 +649,7 @@
 #endif
         }
     }
-    ERR("token buffer exceeded");
+    return TOKEN_BUF_EXCEEDED;
 }
 
 static ScmObj read_quote(ScmObj port, ScmObj quoter)
@@ -649,9 +659,12 @@
 
 static ScmObj read_number(ScmObj port, char prefix)
 {
+    size_t len;
     char buf[INT_LITERAL_LEN_MAX + sizeof((char)'\0')];
 
-    read_token(port, buf, sizeof(buf), DELIMITER_CHARS);
+    len = read_token(port, buf, sizeof(buf), DELIMITER_CHARS);
+    if (len == TOKEN_BUF_EXCEEDED)
+        ERR("invalid number literal");
 
     return parse_number(port, buf, sizeof(buf), prefix);
 }



More information about the uim-commit mailing list