From 578f7361ebe8d8240215f1345bd4c987079174bb Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Sat, 26 Jul 2014 10:40:51 +0200 Subject: [PATCH 1/2] check for overflow during division --- forf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/forf.c b/forf.c index 18e950d..b85de82 100644 --- a/forf.c +++ b/forf.c @@ -30,6 +30,7 @@ #include #include #include +#include #include "forf.h" #include "dump.h" @@ -348,7 +349,7 @@ forf_proc_div(struct forf_env *env) long a = forf_pop_num(env); long b = forf_pop_num(env); - if (0 == a) { + if (0 == a || (a == -1 && b == LONG_MIN)) { env->error = forf_error_divzero; return; } @@ -361,7 +362,7 @@ forf_proc_mod(struct forf_env *env) long a = forf_pop_num(env); long b = forf_pop_num(env); - if (0 == a) { + if (0 == a || (a == -1 && b == LONG_MIN)) { env->error = forf_error_divzero; return; } From ff851a6b07dc3c28eff7f2df9a501fde1043049d Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Sat, 26 Jul 2014 13:48:04 +0200 Subject: [PATCH 2/2] allow simultaneous cannon firing --- ctanks.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ctanks.c b/ctanks.c index f7d1049..7d7c7c5 100644 --- a/ctanks.c +++ b/ctanks.c @@ -116,13 +116,14 @@ tanks_fire_cannon(struct tanks_game *game, float theta = this->angle + this->turret.current; float rpos[2]; - /* If someone's a crater, this is easy */ - if (this->killer || that->killer) { + /* If someone's a crater, this is easy (unless we were just killed by the other one, in which case + we have to check the other direction) */ + if ((this->killer && this->killer != that) || that->killer) { return; } /* Did they collide? */ - if (dist2 < TANK_COLLISION_ADJ2) { + if ((!this->killer) && dist2 < TANK_COLLISION_ADJ2) { this->killer = that; this->cause_death = "collision";