summaryrefslogtreecommitdiffstats
path: root/trek
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2008-11-14 21:10:44 +0000
committerchristos <christos@NetBSD.org>2008-11-14 21:10:44 +0000
commit6c88ea25e68cb2e5c3f3ff06d4d987f4d42a1b59 (patch)
tree16c87857ec39da4a126b21ccc36c73c3667c7f05 /trek
parent2eca29b7a064d9d594bcf4b74834b5ba7f4d3fb7 (diff)
downloadbsdgames-darwin-6c88ea25e68cb2e5c3f3ff06d4d987f4d42a1b59.tar.gz
bsdgames-darwin-6c88ea25e68cb2e5c3f3ff06d4d987f4d42a1b59.tar.zst
bsdgames-darwin-6c88ea25e68cb2e5c3f3ff06d4d987f4d42a1b59.zip
PR/39923: Valery Ushakov: trek(6) can spin, consuming 100% CPU on powerpc
On systems where char is unsigned the number of black holes can end up being very large (instead of negative).
Diffstat (limited to 'trek')
-rw-r--r--trek/setup.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/trek/setup.c b/trek/setup.c
index 1f14f276..cd43ebbe 100644
--- a/trek/setup.c
+++ b/trek/setup.c
@@ -1,4 +1,4 @@
-/* $NetBSD: setup.c,v 1.8 2003/08/07 09:37:54 agc Exp $ */
+/* $NetBSD: setup.c,v 1.9 2008/11/14 21:10:44 christos Exp $ */
/*
* Copyright (c) 1980, 1993
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)setup.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: setup.c,v 1.8 2003/08/07 09:37:54 agc Exp $");
+__RCSID("$NetBSD: setup.c,v 1.9 2008/11/14 21:10:44 christos Exp $");
#endif
#endif /* not lint */
@@ -234,11 +234,14 @@ setup()
for (i = 0; i < NQUADS; i++)
for (j = 0; j < NQUADS; j++)
{
+ short s5;
q = &Quad[i][j];
q->klings = q->bases = 0;
q->scanned = -1;
q->stars = ranf(9) + 1;
- q->holes = ranf(3) - q->stars / 5;
+ q->holes = ranf(3);
+ s5 = q->stars / 5;
+ q->holes = q->holes > s5 ? q->holes - s5 : 0;
q->qsystemname = 0;
}