help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] Segfault while handling a Symbol literal


From: Paolo Bonzini
Subject: Re: [Help-smalltalk] Segfault while handling a Symbol literal
Date: Wed, 28 Mar 2007 08:38:51 +0200
User-agent: Thunderbird 1.5.0.10 (Macintosh/20070221)

Jānis Rūcis wrote:
> While playing with various combinations of characters in Symbol literals
> I discovered that a negative number, as in "#-123", causes a memory
> access violation.  The code is just way over my head so I wasn't able to
> figure out a fix for it...  But while I was looking at it, I noticed a
> typo in print_token, in libgst/lex.c and fixed that instead.  :P  See
> the attached patch.

Here's the fix, it will be in 2.3.4.

Thanks,

Paolo
2007-03-28  Paolo Bonzini  <address@hidden>

        * libgst/lex.c: Fix parsing of #-123.


--- orig/libgst/lex.c
+++ mod/libgst/lex.c
@@ -140,7 +140,14 @@ static int char_literal (int c,
 
 /* Parse a binary operator.  C is the first symbol in the selector */
 static int scan_bin_op (int c,
-                        YYSTYPE * lvalp);
+                       YYSTYPE * lvalp);
+
+/* Actual work for scan_bin_op is done here.  MAYBE_NUMBER is false if
+   we cannot parse a negative number in this context.  */ 
+static int scan_bin_op_1 (int c,
+                         YYSTYPE * lvalp,
+                         mst_Boolean maybe_number);
+
 
 /* Parse a string literal.  C is '\'' */
 static int string_literal (int c,
@@ -487,7 +494,7 @@ scan_symbol (int c,
   /* We can read a binary operator and return a SYMBOL_LITERAL,... */
   if (CHAR_TAB (ic)->char_class & BIN_OP_CHAR)
     {
-      scan_bin_op (ic, lvalp);
+      scan_bin_op_1 (ic, lvalp, false);
       return SYMBOL_LITERAL;
     }
 
@@ -519,8 +526,9 @@ scan_symbol (int c,
 
 
 int
-scan_bin_op (int c,
-             YYSTYPE *lvalp)
+scan_bin_op_1 (int c,
+              YYSTYPE *lvalp,
+              mst_Boolean maybe_number)
 {
   char buf[3];
   int ic;
@@ -551,7 +559,7 @@ scan_bin_op (int c,
 
       /* We come here also for a negative number, which we handle
          specially.  */
-      if (c == '-' && is_digit (ic))
+      if (maybe_number && c == '-' && is_digit (ic))
        return (scan_number ('-', lvalp));
 
       buf[1] = 0;
@@ -568,6 +576,13 @@ scan_bin_op (int c,
 }
 
 int
+scan_bin_op (int c,
+            YYSTYPE *lvalp)
+{
+  return scan_bin_op_1 (c, lvalp, true);
+}
+
+int
 string_literal (int c,
                YYSTYPE * lvalp)
 {


--- orig/tests/compiler.st
+++ mod/tests/compiler.st
@@ -108,3 +108,10 @@ c
     ^'foo'! !
 
 ^BugTest c!
+
+"The lexer crashed on this because it returned a SYMBOL_LITERAL with
+ -123 in the ival.  This gives a parse error..."
+^#-123!
+
+"... this does not."
+^#(#-123) size!



* added files

--- /dev/null
+++ 
/Volumes/disk0s8/devel/gst-stable/,,address@hidden/new-files-archive/./{arch}/smalltalk/smalltalk--devo/smalltalk--devo--2.2/address@hidden/patch-log/patch-286
@@ -0,0 +1,15 @@
+Revision: smalltalk--devo--2.2--patch-286
+Archive: address@hidden
+Creator: Paolo Bonzini <address@hidden>
+Date: Wed Mar 28 08:35:29 CEST 2007
+Standard-date: 2007-03-28 06:35:29 GMT
+Modified-files: libgst/ChangeLog libgst/lex.c
+    tests/compiler.st
+New-patches: address@hidden/smalltalk--devo--2.2--patch-286
+Summary: fix parsing of #-123
+Keywords: 
+
+2007-03-28  Paolo Bonzini  <address@hidden>
+
+       * libgst/lex.c: Fix parsing of #-123.
+


reply via email to

[Prev in Thread] Current Thread [Next in Thread]