tree CHANGE test for NULL in LY_ARRAY_COUNT() macro
Make it more safe in cost of losing possibility to use macro as lvalue.
diff --git a/src/tree.h b/src/tree.h
index 911addb..cc8799b 100644
--- a/src/tree.h
+++ b/src/tree.h
@@ -140,15 +140,13 @@
*/
#define LY_ARRAY_FOR_INDEX(ARRAY, INDEX) \
for (INDEX = 0; \
- ARRAY && INDEX < (*((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1)); \
+ INDEX < LY_ARRAY_COUNT(ARRAY); \
++INDEX)
/**
* @brief Get the number of records in the ARRAY.
- *
- * Does not check if array exists!
*/
-#define LY_ARRAY_COUNT(ARRAY) (*((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1))
+#define LY_ARRAY_COUNT(ARRAY) (ARRAY ? (*((LY_ARRAY_COUNT_TYPE*)(ARRAY) - 1)) : 0)
/**
* @brief Sized-array iterator (for-loop).