Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Prevent store-restocking faults from hanging the game in an infinite …

…loop

Signed-off-by: Peter Denison <angband@marshadder.org>
  • Loading branch information...
commit c5913483279cb4f51eb19266e14be945ce3321a4 1 parent f99301b
@pnd10 pnd10 authored
Showing with 8 additions and 3 deletions.
  1. +8 −3 src/store.c
View
11 src/store.c
@@ -1546,6 +1546,7 @@ void store_maint(int which)
struct cave c;
struct cave *oldcave;
store_type *st_ptr;
+ int restock_attempts = 100000;
/* Some of the functions we call gratuitously adjust the rating, and
* we'd like that not to happen for the town. Create a temporary cave
@@ -1620,9 +1621,13 @@ void store_maint(int which)
if (stock < STORE_MIN_KEEP) stock = STORE_MIN_KEEP;
/* For the rest, we just choose items randomlyish */
- /* XXX this means that we can get stuck in infinite loops if stores
- * don't have enough items they can stock! */
- while (st_ptr->stock_num < stock) store_create_random(which);
+ /* The (huge) restock_attempts will only go to zero (otherwise
+ * infinite loop) if stores don't have enough items they can stock! */
+ while (st_ptr->stock_num < stock && --restock_attempts)
+ store_create_random(which);
+
+ if(!restock_attempts)
+ quit_fmt("Unable to (re-)stock store %d. Please report this bug", which);
cave = oldcave;
}
Please sign in to comment.
Something went wrong with that request. Please try again.