View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update | 
|---|---|---|---|---|---|
| 0000503 | LDMud 3.3 | Runtime | public | 2007-04-25 17:02 | 2018-01-29 21:57 | 
| Reporter | zesstra | Assigned To | |||
| Priority | normal | Severity | major | Reproducibility | always | 
| Status | resolved | Resolution | fixed | ||
| Product Version | 3.3.713 | ||||
| Fixed in Version | 3.3.716 | ||||
| Summary | 0000503: foreach() with negative integer expression causes "endless" loop | ||||
| Description | foreach(int i: -1) printf("%O",i); loops as long as there are evaluation ticks left: "...6503186504186505186506186507186508186509186510186511186512186513186514186515186516186517186518186519186520186521186522186523186524186525186526186527186528186529186530186531186532186533186534186535186536186537186538186539186540186541Error: Too long evaluation. Execution aborted."  | ||||
| Additional Information | I will probably look into the source during the next days and try to write a suitable patch. | ||||
| Tags | No tags attached. | ||||
| Attached Files |  foreach.patch (446 bytes)   
 
--- ldmud-3.3.714.orig/src/interpret.c	2006-07-10 04:44:33.000000000 +0200
+++ ldmud-3.3.714/src/interpret.c	2007-04-29 23:33:15.000000000 +0200
@@ -15165,6 +15165,8 @@
         if (arg->type == T_NUMBER)
         {
             count = arg->u.number;
+            if (count<0)
+              ERRORF(("foreach() got %ld, expected a positive integer.\n",count));
             vars_required = 1;
         }
         else if (arg->type == T_STRING)
 foreach2.patch (460 bytes)   
 
--- ldmud-3.3.714.orig/src/interpret.c	2006-07-10 04:44:33.000000000 +0200
+++ ldmud-3.3.714/src/interpret.c	2007-04-29 23:55:34.000000000 +0200
@@ -15165,6 +15165,8 @@
         if (arg->type == T_NUMBER)
         {
             count = arg->u.number;
+            if (count<0 && !use_range)
+              ERRORF(("foreach() got %ld, expected a positive integer.\n",count));
             vars_required = 1;
         }
         else if (arg->type == T_STRING)
 | ||||
| 
		 | 
	
	Ok, this is a tiny patch for interpret.c which just checks 'count' in CASE(F_FOREACH) if the argument is of type T_NUMBER. If 'count' is negative, it throws an error via ERRORF(). One could argue that the original behaviour is not a bug and just a possibility to iterate over a larger integer range than 0 - MAX_INT. But I think, that isn't a very realistic scenario. Most often, a negative integer as range expression is just not intended and therefore I would prefer to not accept it. BTW: Another possibility is to silently correct a negative 'count' to 0 and only issue a warning, but I would definitely prefer a real error as this situation anyway leads to a 'too long evalution' error.  | 
| 
		 | 
	Yup, makes sense. | 
| Date Modified | Username | Field | Change | 
|---|---|---|---|
| 2007-04-25 17:02 | zesstra | New Issue | |
| 2007-04-29 15:36 | zesstra | File Added: foreach.patch | |
| 2007-04-29 15:47 | zesstra | Note Added: 0000531 | |
| 2007-04-29 16:01 | zesstra | File Added: foreach2.patch | |
| 2007-10-06 22:40 | 
					 | 
				Status | new => resolved | 
| 2007-10-06 22:40 | 
					 | 
				Fixed in Version | => 3.3.716 | 
| 2007-10-06 22:40 | 
					 | 
				Resolution | open => fixed | 
| 2007-10-06 22:40 | 
					 | 
				Assigned To | => lars | 
| 2007-10-06 22:40 | 
					 | 
				Note Added: 0000560 | |
| 2010-11-16 09:42 | 
					 | 
				Source_changeset_attached | => ldmud.git master 3bf94a56 | 
| 2018-01-29 18:59 | 
					 | 
				Source_changeset_attached | => ldmud.git master 3bf94a56 | 
| 2018-01-29 21:57 | 
					 | 
				Source_changeset_attached | => ldmud.git master 3bf94a56 |