diff options
| author | 2024-11-16 21:20:26 -0800 | |
|---|---|---|
| committer | 2024-11-16 21:20:26 -0800 | |
| commit | e2eb7ab4b2eae9be176bf11c0230f861cb1ffce5 (patch) | |
| tree | 4dfd099f28e9ca267bd8b329f68dc58474a703d2 | |
| parent | Merge 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.c | 4 |
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); } |
