diff --git a/lib/src/clixon_xml_diff.c b/lib/src/clixon_xml_diff.c index fddc7c308..e94928204 100644 --- a/lib/src/clixon_xml_diff.c +++ b/lib/src/clixon_xml_diff.c @@ -539,7 +539,7 @@ xml_diff(cxobj *x0, goto ok; } if (x0 == NULL){ - if (cxvec_append(x0, second, secondlen) < 0) + if (cxvec_append(x1, second, secondlen) < 0) goto done; goto ok; } diff --git a/lib/src/clixon_xpath_eval.c b/lib/src/clixon_xpath_eval.c index d181d84cf..c8677412c 100644 --- a/lib/src/clixon_xpath_eval.c +++ b/lib/src/clixon_xpath_eval.c @@ -763,7 +763,9 @@ xp_numop(xp_ctx *xc1, xr->xc_number = n1/n2; break; case XO_MOD: - xr->xc_number = ((int)n1)%((int)n2); + /* XPath 1.0 3.5: remainder from a truncating division, as fmod(). + * Integer % crashes with SIGFPE if n2 truncates to 0 */ + xr->xc_number = fmod(n1, n2); break; case XO_ADD: xr->xc_number = n1+n2; diff --git a/test/test_xpath.sh b/test/test_xpath.sh index 1fa2632ed..039735424 100755 --- a/test/test_xpath.sh +++ b/test/test_xpath.sh @@ -412,6 +412,25 @@ expectpart "$($clixon_util_xpath -D $DBG -f $xml2 -p "string-length(\"12345\")") new "xpath string-length path" expectpart "$($clixon_util_xpath -D $DBG -f $xml2 -p "string-length(aaa/name)")" 0 "number:3" +# mod: XPath 1.0 3.5, remainder from a truncating division +new "xpath 5 mod 2" +expectpart "$($clixon_util_xpath -D $DBG -f $xml2 -p "5 mod 2")" 0 "number:1.0" + +new "xpath 5 mod -2" +expectpart "$($clixon_util_xpath -D $DBG -f $xml2 -p "5 mod -2")" 0 "number:1.0" + +new "xpath -5 mod 2" +expectpart "$($clixon_util_xpath -D $DBG -f $xml2 -p "-5 mod 2")" 0 "number:-1.0" + +new "xpath 5.5 mod 2" +expectpart "$($clixon_util_xpath -D $DBG -f $xml2 -p "5.5 mod 2")" 0 "number:1.5" + +new "xpath 1 mod 0 is NaN, not crash" +expectpart "$($clixon_util_xpath -D $DBG -f $xml2 -p "1 mod 0")" 0 "number:" "nan" + +new "xpath 1 mod 0.5, divisor truncated to int was 0" +expectpart "$($clixon_util_xpath -D $DBG -f $xml2 -p "1 mod 0.5")" 0 "number:0.0" + # translate new "xpath translate" # modified expectpart "$($clixon_util_xpath -D $DBG -f $xml2 -p "translate(\"bar\", \"abc\",\"DEF\")")" 0 "string:EDr$"