set UPDATE check input vars
diff --git a/src/set.c b/src/set.c
index c7fedf8..f36ab5f 100644
--- a/src/set.c
+++ b/src/set.c
@@ -230,6 +230,8 @@
 LIBYANG_API_DEF LY_ERR
 ly_set_rm_index_ordered(struct ly_set *set, uint32_t index, void (*destructor)(void *obj))
 {
+    LY_CHECK_ARG_RET(NULL, set, set->count, LY_EINVAL);
+
     if (destructor) {
         destructor(set->objs[index]);
     }