I found after some time another case which causes CLIPS to crash in the FactJNGetVar3 function. Tried it with the latest sources. Could You check it, please:
During pattern matching variables are retrieved from partial matches. The index for retrieval was being computed incorrectly in some cases. Here's a simpler example that has the same issue:
What was the problem, what combinations of expressions were affected by this bug? What types may still be endangered?
I temporarily worked-around the crash by joining duplicated facts in the LHS. Is it the substance of the problem? Can it have any performance consequences (speedup)?
I have one more example that was causing a crash, do You also want to analýze it od shall I just try the fix?
Thanks Vranoch
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Go ahead and post the example. It's always good to have more than occurrence of a bug for regression testing even if the existing fix covers it.
I used a different approach for building the rete network in earlier versions of 6.3, but then reverted to the method used by 6.24 in the final release. I missed a piece of code when rolling back changes. The simplest piece of code that I could derive from your original example that crashed was this:
You have to have several levels of nested not/exists containing multiple patterns and more than one grouping closed before the next pattern is encountered (such as after the Z pattern). Pattern indices for retrieving variables need to be computed correctly and normally for simple rules which do not contain multiple patterns within a not/exist, the index for the Nth pattern in the rule is N-1. In this example, the index for pattern C needs to be 1 and pattern D needs to be 2, but these were incorrectly computed as 2 and 3. The crash was caused by attempting to access an element beyond the valid length of an array. I wouldn't expect this to have performance consequences, but it's possible that there were cases where the wrong index was being used for retrieving a variable that didn't cause a crash and that this might have made a difference in the amount of computation that a rule had to do.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Gary,
I found after some time another case which causes CLIPS to crash in the FactJNGetVar3 function. Tried it with the latest sources. Could You check it, please:
rule:
facts:
Thanks Vranoch
I'll take a look.
Checked in a fix to the subversion repository
Thanks Gary, what was the problem?
During pattern matching variables are retrieved from partial matches. The index for retrieval was being computed incorrectly in some cases. Here's a simpler example that has the same issue:
In this case, the comparison of the variable ?v from the SAD pattern was using an index that was 1 larger than it should have been.
Hi Gary,
I found another occurrence of this problem:
rule:
~~~~~~~~~~~~~~~~~~~~~~
(defrule if ""
(exists
(or
(exists
(SAD H H04 ?h04)
(SAD G ?ix_g G11 ?g11)
(or
(and
(test (> (str-length ?h04) 0))
(test (not (not (str-index ?h04 "IR,IN,SY,KP,TR,AE"))))
)
(and
(test (> (str-length ?g11) 0))
(test (not (not (str-index ?g11 "IR,IN,SY,KP,TR,AE"))))
)
)
)
(exists
(SAD T ?ix_t T05 ?t05)
(SAD T ?ix_t T05 ?t05)
(and
(test (> (str-length ?t05) 0))
(test (not (not (str-index ?t05 "IR,IN,SY,KP,TR,AE"))))
)
)
)
)
=>
)
(SAD H H04 "SG")
(SAD G 1 G11 "SG")
(SAD T 1 T05 "BE")
~~~~~~~~~~~~~~~~~~~~~~~~
Could You look at it, please?
Thanks Vranoch
I'll take a look.
A fix has been checked into the SVN repository.
Thanks a lot Gary,
What was the problem, what combinations of expressions were affected by this bug? What types may still be endangered?
I temporarily worked-around the crash by joining duplicated facts in the LHS. Is it the substance of the problem? Can it have any performance consequences (speedup)?
I have one more example that was causing a crash, do You also want to analýze it od shall I just try the fix?
Thanks Vranoch
Go ahead and post the example. It's always good to have more than occurrence of a bug for regression testing even if the existing fix covers it.
I used a different approach for building the rete network in earlier versions of 6.3, but then reverted to the method used by 6.24 in the final release. I missed a piece of code when rolling back changes. The simplest piece of code that I could derive from your original example that crashed was this:
You have to have several levels of nested not/exists containing multiple patterns and more than one grouping closed before the next pattern is encountered (such as after the Z pattern). Pattern indices for retrieving variables need to be computed correctly and normally for simple rules which do not contain multiple patterns within a not/exist, the index for the Nth pattern in the rule is N-1. In this example, the index for pattern C needs to be 1 and pattern D needs to be 2, but these were incorrectly computed as 2 and 3. The crash was caused by attempting to access an element beyond the valid length of an array. I wouldn't expect this to have performance consequences, but it's possible that there were cases where the wrong index was being used for retrieving a variable that didn't cause a crash and that this might have made a difference in the amount of computation that a rule had to do.