Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] (PR#10107) a CHECK_NATIVE_POS macro
Home

[Freeciv-Dev] (PR#10107) a CHECK_NATIVE_POS macro

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients: ;
Subject: [Freeciv-Dev] (PR#10107) a CHECK_NATIVE_POS macro
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 14 Sep 2004 10:34:45 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=10107 >

This patch adds a CHECK_NATIVE_POS macro.  It is called in 
native_pos_to_index.  This can help catch some map errors a little sooner.

jason

Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.214
diff -u -r1.214 map.h
--- common/map.h        14 Sep 2004 08:22:59 -0000      1.214
+++ common/map.h        14 Sep 2004 17:34:06 -0000
@@ -234,14 +234,18 @@
 
 #ifdef DEBUG
 #define CHECK_MAP_POS(x,y) assert(is_normal_map_pos((x),(y)))
+#define CHECK_NATIVE_POS(x, y) assert((x) >= 0 && (x) < map.xsize \
+                                     && (y) >= 0 && (y) < map.ysize)
 #define CHECK_INDEX(index) assert((index) >= 0 && (index) < MAX_MAP_INDEX)
 #else
 #define CHECK_MAP_POS(x,y) ((void)0)
+#define CHECK_NATIVE_POS(x, y) ((void)0)
 #define CHECK_INDEX(index) ((void)0)
 #endif
 
 #define native_pos_to_index(nat_x, nat_y)                                   \
-  ((nat_x) + (nat_y) * map.xsize)
+  (CHECK_NATIVE_POS((nat_x,), (nat_y)),                                        
    \
+   (nat_x) + (nat_y) * map.xsize)
 #define index_to_native_pos(pnat_x, pnat_y, index)                          \
   (*(pnat_x) = (index) % map.xsize,                                         \
    *(pnat_y) = (index) / map.xsize)

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#10107) a CHECK_NATIVE_POS macro, Jason Short <=