Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/clixon_xml_diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 3 additions & 1 deletion lib/src/clixon_xpath_eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions test/test_xpath.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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$"
Expand Down
Loading