diff --git a/relaxng.c b/relaxng.c
index f34dc14..16d8b46 100644
--- a/relaxng.c
+++ b/relaxng.c
@@ -1095,7 +1095,7 @@ xmlRelaxNGAddStates(xmlRelaxNGValidCtxtPtr ctxt,
 {
     int i;
 
-    if (state == NULL) {
+    if (state == NULL || states == NULL) {
         return (-1);
     }
     if (states->nbState >= states->maxState) {
