Christophe doesn't believe in error checking. I, however, have
been tripping over them all the time.
References: bnc#469269
Signed-off-by: Hannes Reinecke <hare@suse.de>
typedef struct _vector *vector;
#define VECTOR_DEFAULT_SIZE 1
-#define VECTOR_SLOT(V,E) ((V)->slot[(E)])
-#define VECTOR_SIZE(V) ((V)->allocated)
-#define VECTOR_LAST_SLOT(V) ((V)->slot[((V)->allocated - 1)])
+#define VECTOR_SLOT(V,E) (((V) && (E) < (V)->allocated) ? (V)->slot[(E)] : NULL)
+#define VECTOR_SIZE(V) ((V) ? (V)->allocated : 0)
+#define VECTOR_LAST_SLOT(V) (((V) && (V)->allocated) ? (V)->slot[((V)->allocated - 1)] : NULL)
#define vector_foreach_slot(v,p,i) \
for (i = 0; (v) && i < (v)->allocated && ((p) = (v)->slot[i]); i++)