aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
authorJade Lovelace <lix@jade.fyi>2024-07-12 14:56:30 +0200
committerJade Lovelace <lix@jade.fyi>2024-07-12 16:48:28 +0200
commitdde51af97df647e423943d63b5f65b55bf35d811 (patch)
tree7599bf76cba6c00f36a0bc7854df33ac02e92863 /src/libexpr
parent4b109ec1a8fc4550150f56f0f46f2f41d844bda8 (diff)
Use std::strong_ordering for version comparison
The actual motive here is the avoidance of integer overflow if we were to make these use checked NixInts and retain the subtraction. However, the actual *intent* of this code is a three-way comparison, which can be done with operator<=>, so we should just do *that* instead. Change-Id: I7f9a7da1f3176424b528af6d1b4f1591e4ab26bf
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/primops.cc3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 72ae1aeb9..80c64232f 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -4162,7 +4162,8 @@ static void prim_compareVersions(EvalState & state, const PosIdx pos, Value * *
{
auto version1 = state.forceStringNoCtx(*args[0], pos, "while evaluating the first argument passed to builtins.compareVersions");
auto version2 = state.forceStringNoCtx(*args[1], pos, "while evaluating the second argument passed to builtins.compareVersions");
- v.mkInt(compareVersions(version1, version2));
+ auto result = compareVersions(version1, version2);
+ v.mkInt(result < 0 ? -1 : result > 0 ? 1 : 0);
}
static RegisterPrimOp primop_compareVersions({