vlvassilev / yuma123

The yuma123 repository
Other
24 stars 28 forks source link

ncx_compare_nums() has a non working optimization #143

Open jonaslindahl opened 8 months ago

jonaslindahl commented 8 months ago

The following code from ncx_compare_nums() does not work

            /* check if any leading zeroes */
            if (temp1 == 0) {
                if (num1->dec.zeroes < num2->dec.zeroes) {
                    return 1;
                } else if (num1->dec.zeroes > num2->dec.zeroes) {
                    return -1;
                }  /* else need to compare fraction parts */
            }

It fails for cases where dec.zeroes == 0 due to dec.val == 0. Either tremove this code entirely or add cases to cover situations where dec.zeroes == 0 due to dec.val == 0.

Example:

leaf sample-configuration {
  type decimal64 { fraction-digits 4; range "0 .. 1.9999";}
  default 0.001;
}

yangdump will consider the default value of 0.001 invalid since num1->dec.zeroes == 2 > num2->dec-zeroes == 0 causing return -1 while comparing the lower range (0)

vlvassilev commented 7 months ago

Confirmed. Added testcase 707d917d3f48ea1425b677cc9c076661bc628d1d . High priority issue.