common: introduce bt_g_array_index
[babeltrace.git] / src / common / macros.h
index 533cb9fb56eab9127540004c533b38d86d8c74c1..ad4218c445f98caf104223b1499783f70ceb209d 100644 (file)
@@ -52,6 +52,10 @@ extern "C" {
                _ref;                   \
        })
 
+/* Wrapper for g_array_index that adds bound checking.  */
+#define bt_g_array_index(a, t, i)              \
+       g_array_index((a), t, ({ BT_ASSERT_DBG((i) < (a)->len); (i); }))
+
 /*
  * Copied from:
  * <https://stackoverflow.com/questions/37411809/how-to-elegantly-fix-this-unused-variable-warning/37412551#37412551>:
This page took 0.024264 seconds and 4 git commands to generate.