diff --git a/src/lexer.h b/src/lexer.h
index 7a9e7438a3cc0eb8b3ea4f40c225073aa0c04304..aad36b9f93ae27e1fdeae3048f3d073af18ad475 100644
--- a/src/lexer.h
+++ b/src/lexer.h
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: lexer.h,v 1.84 2008/06/29 21:33:25 marcus Exp $
+|| $Id: lexer.h,v 1.85 2008/07/22 23:35:13 mast Exp $
 */
 
 /*
@@ -878,12 +878,12 @@ static int low_yylex(struct lex *lex, YYSTYPE *yylval)
 	sval.type = PIKE_T_INT;
 	sval.subtype = NUMBER_NUMBER;
 	sval.u.integer = 0;
-	wide_string_to_svalue_inumber(&sval,
-				      lex->pos,
-				      &lex->pos,
-				      base,
-				      0,
-				      SHIFT);
+	safe_wide_string_to_svalue_inumber(&sval,
+					   lex->pos,
+					   &lex->pos,
+					   base,
+					   0,
+					   SHIFT);
 	dmalloc_touch_svalue(&sval);
 	yylval->n = mksvaluenode(&sval);
 	free_svalue(&sval);
@@ -914,12 +914,12 @@ static int low_yylex(struct lex *lex, YYSTYPE *yylval)
       sval.subtype = NUMBER_NUMBER;
       sval.u.integer = 0;      
 
-      wide_string_to_svalue_inumber(&sval,
-				    lex->pos,
-				    &p2,
-				    0,
-				    0,
-				    SHIFT);
+      safe_wide_string_to_svalue_inumber(&sval,
+					 lex->pos,
+					 &p2,
+					 0,
+					 0,
+					 SHIFT);
       if(p1>p2)
       {
 	/* Floating point or version. */
@@ -931,12 +931,12 @@ static int low_yylex(struct lex *lex, YYSTYPE *yylval)
 	  dmalloc_touch_svalue(&sval);
 
 	  sval.u.integer = 0;
-	  wide_string_to_svalue_inumber(&sval,
-					p2,
-					&p3,
-					0,
-					0,
-					SHIFT);
+	  safe_wide_string_to_svalue_inumber(&sval,
+					     p2,
+					     &p3,
+					     0,
+					     0,
+					     SHIFT);
 	  dmalloc_touch_svalue(&sval);
 	  if ((sval.type == PIKE_T_INT) && (p3 > p2)) {
 	    for (l=0; ISSPACE(INDEX_CHARP(p3, l, SHIFT)); l++)
diff --git a/src/stralloc.c b/src/stralloc.c
index 1200806557f95c3ec411805b7a1613708eaaccfe..e1a5e5ad054523ea9083e7db838426fa436f5a79 100644
--- a/src/stralloc.c
+++ b/src/stralloc.c
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: stralloc.c,v 1.230 2008/07/18 01:42:49 mast Exp $
+|| $Id: stralloc.c,v 1.231 2008/07/22 23:35:12 mast Exp $
 */
 
 #include "global.h"
@@ -3184,6 +3184,38 @@ PMOD_EXPORT int wide_string_to_svalue_inumber(struct svalue *r,
   return ret;
 }
 
+int safe_wide_string_to_svalue_inumber(struct svalue *r,
+				       void * str,
+				       void *ptr,
+				       int base,
+				       ptrdiff_t maxlength,
+				       int shift)
+/* For use from the lexer where we can't let errors be thrown. */
+{
+  PCHARP tmp;
+  JMP_BUF recovery;
+  int ret = 0;
+
+  free_svalue (&throw_value);
+  mark_free_svalue (&throw_value);
+
+  if (SETJMP (recovery)) {
+    /* We know that pcharp_to_svalue_inumber has initialized the
+     * svalue before any error might be thrown. */
+    call_handle_error();
+    ret = 0;
+  }
+  else
+    ret = pcharp_to_svalue_inumber(r,
+				   MKPCHARP(str,shift),
+				   &tmp,
+				   base,
+				   maxlength);
+  UNSETJMP (recovery);
+  if(ptr) *(p_wchar0 **)ptr=tmp.ptr;
+  return ret;
+}
+
 PMOD_EXPORT int pcharp_to_svalue_inumber(struct svalue *r,
 					 PCHARP str,
 					 PCHARP *ptr,
diff --git a/src/stralloc.h b/src/stralloc.h
index a6fa4a804fa4fb654641e206739d318a6dd985d9..0bada4871442b7718e76c1d3623d217eeba568c0 100644
--- a/src/stralloc.h
+++ b/src/stralloc.h
@@ -2,7 +2,7 @@
 || This file is part of Pike. For copyright information see COPYRIGHT.
 || Pike is distributed under GPL, LGPL and MPL. See the file COPYING
 || for more information.
-|| $Id: stralloc.h,v 1.109 2008/06/30 22:13:29 marcus Exp $
+|| $Id: stralloc.h,v 1.110 2008/07/22 23:35:11 mast Exp $
 */
 
 #ifndef STRALLOC_H
@@ -396,6 +396,12 @@ PMOD_EXPORT int wide_string_to_svalue_inumber(struct svalue *r,
 					      int base,
 					      ptrdiff_t maxlength,
 					      int shift);
+int safe_wide_string_to_svalue_inumber(struct svalue *r,
+				       void * str,
+				       void *ptr,
+				       int base,
+				       ptrdiff_t maxlength,
+				       int shift);
 PMOD_EXPORT int pcharp_to_svalue_inumber(struct svalue *r,
 					 PCHARP str,
 					 PCHARP *ptr,