diff options
author | Joshua Judson Rosen | 2017-03-19 16:34:33 -0400 |
---|---|---|
committer | Joshua Judson Rosen | 2017-03-28 22:07:50 -0400 |
commit | 8998d7b95cddbb8a5103f753476927f9584a30b0 (patch) | |
tree | 7e8a0c50210ccf7f9f1dc11b9fae78a6167a2cb3 | |
parent | robot-move: update display regardless of whether movement succeeded (diff) | |
download | gnurobots-8998d7b95cddbb8a5103f753476927f9584a30b0.tar.gz |
robot-move: prevent crash on zero-length moves
-rw-r--r-- | include/grobot.h | 5 |
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; |