-
Notifications
You must be signed in to change notification settings - Fork 123
elektraKeyCmpOrder with order = 0 #3274
Comments
Thank you for reporting this bug!
No.
Sounds like a bug, an assert would have been helpful there. Feel free to change the implementation of elektraKeyCmpOrder as you want. One idea was to also allow suborders like 0.1.2. This might be useful for sections (the first number counts the section, the second the key and so on). In any case, please improve the docu in doc/METADATA.ini. At the moment the docu does not contain any example, nor which range of numbers is allowed (which seems to have made you very unsure if this is a bug). |
If we prefix the integer(s) with int elektraKeyCmpOrder (const Key * ka, const Key * kb)
{
// keyGetMeta is NULL, if key is NULL
const Key * kam = keyGetMeta (ka, "order");
const Key * kbm = keyGetMeta (kb, "order");
if (ka == kb) return 0; // same pointer (including both NULL)
if (ka == NULL) return -1;
if (kb == NULL) return 1;
return strcmp (keyString (kam), keyString(kbm));
} If the special case for negative numbers has to be preserved, this won't work of course. |
Yes, having a simple strcmp with with /#1/#_10 arrays would also be possible. But this would require to rewrite all plugins.... |
Fixes ElektraInitiative#3274. The elektraKeyCmpOrder function no longer considers order values of 0 as equal with any other positive integer.
will be closed by #3292 |
Keys with order zero or less are now sorted properly.
Keys with order zero or less are now sorted properly.
Keys with order zero or less are now sorted properly.
Does a order metakey with value 0 have any special meaning (I couldn't find any information on it in
METADATA.ini
)?Otherwise I think the
elektraKeyCmpOrder
function does not work as intended. While working on the toml plugin, I got an unexpected ordering of my Key array after sorting it with the help ofelektraKeyCmpOrder
.Expected Result
I expected a Key with order metakey 0 to be sorted before a key with order 1.
Actual Result
The Key with order = 0 wasn't sorted as first element, but between the keys with order 101 and 102.
Steps to Reproduce the Problem
When I looked into the implementation of
elektraKeyCmpOrder
I saw that when I compare 0 with any other positive number, none of the if branches will get taken and thereturn 0
is taken, after thecannot happen anyway
comment.Relevant
elektraKeyCmpOrder
code:For example, let aorder be 0 and border be 1, then no branch is taken since
or if aorder = 1 and border = 0
For both cases the function returns 0, meaning that the keys are equal in ordering.
The text was updated successfully, but these errors were encountered: