summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Judson Rosen2017-03-19 16:34:33 -0400
committerJoshua Judson Rosen2017-03-28 22:07:50 -0400
commit8998d7b95cddbb8a5103f753476927f9584a30b0 (patch)
tree7e8a0c50210ccf7f9f1dc11b9fae78a6167a2cb3
parentrobot-move: update display regardless of whether movement succeeded (diff)
downloadgnurobots-8998d7b95cddbb8a5103f753476927f9584a30b0.tar.gz
robot-move: prevent crash on zero-length moves
-rw-r--r--include/grobot.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/include/grobot.h b/include/grobot.h
index 52a7039..60796a9 100644
--- a/include/grobot.h
+++ b/include/grobot.h
@@ -66,7 +66,10 @@ struct _GRobotClass {
/* some convenient macros */
#define G_ROBOT_POSITION_X(robot) ((robot)->x)
#define G_ROBOT_POSITION_Y(robot) ((robot)->y)
-#define sign(x) (x/abs(x))
+
+/* this is a little weird, but 0 case doesn't actually matter
+ given how the code in grobot.c uses this macro... */
+#define sign(x) (x ? x/abs(x) : 0)
/* normal GObject stuff */
GType g_robot_get_type(void) G_GNUC_CONST;