aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIan Henry <ianthehenry@gmail.com>2024-11-16 21:20:26 -0800
committerIan Henry <ianthehenry@gmail.com>2024-11-16 21:20:26 -0800
commite2eb7ab4b2eae9be176bf11c0230f861cb1ffce5 (patch)
tree4dfd099f28e9ca267bd8b329f68dc58474a703d2
parentMerge pull request #1518 from pyrmont/bugfix.s390x-workflow (diff)
fix janet_string_equalconst
Check string length before pointer equality, so that a string is not considered equal to a prefix slice of itself.
-rw-r--r--src/core/string.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/core/string.c b/src/core/string.c
index 277b1a25..6a67482c 100644
--- a/src/core/string.c
+++ b/src/core/string.c
@@ -71,10 +71,10 @@ int janet_string_compare(const uint8_t *lhs, const uint8_t *rhs) {
int janet_string_equalconst(const uint8_t *lhs, const uint8_t *rhs, int32_t rlen, int32_t rhash) {
int32_t lhash = janet_string_hash(lhs);
int32_t llen = janet_string_length(lhs);
- if (lhs == rhs)
- return 1;
if (lhash != rhash || llen != rlen)
return 0;
+ if (lhs == rhs)
+ return 1;
return !memcmp(lhs, rhs, rlen);
}