Replace the type-checking COMPTR macro with my current idea of best
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 22 Jul 2013 07:12:15 +0000 (07:12 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Mon, 22 Jul 2013 07:12:15 +0000 (07:12 +0000)
practice in type-check macros.

git-svn-id: svn://svn.tartarus.org/sgt/putty@9963 cda61777-01e9-0310-a592-d414129be87e

windows/winjump.c

index abefe44..f674133 100644 (file)
@@ -353,12 +353,12 @@ static const PROPERTYKEY PKEY_Title = {
     0x00000002
 };
 
-/* Type-checking macro to provide arguments for CoCreateInstance() etc.
- * The pointer arithmetic is a compile-time pointer type check that 'obj'
- * really is a 'type **', but is intended to have no effect at runtime. */
+/* Type-checking macro to provide arguments for CoCreateInstance()
+ * etc, ensuring that 'obj' really is a 'type **'. */
+#define typecheck(checkexpr, result) \
+    (sizeof(checkexpr) ? (result) : (result))
 #define COMPTR(type, obj) &IID_##type, \
-    (void **)(void *)((obj) + (sizeof((obj)-(type **)(obj))) \
-                           - (sizeof((obj)-(type **)(obj))))
+    typecheck((obj)-(type **)(obj), (void **)(void *)(obj))
 
 static char putty_path[2048];