diff options
author | Heikki Kallasjoki <fis@zem.fi> | 2018-11-16 22:02:08 +0000 |
---|---|---|
committer | Heikki Kallasjoki <fis@zem.fi> | 2018-11-16 22:02:08 +0000 |
commit | f771790b633f02f3857689e9848b0756aeb30b98 (patch) | |
tree | e50dd29b7b217396265cd07709c1e00b3880b59d /util.c | |
parent | e30fd51e676a9d03286c6dce5950314019800de4 (diff) | |
download | nano-exporter-f771790b633f02f3857689e9848b0756aeb30b98.tar.gz nano-exporter-f771790b633f02f3857689e9848b0756aeb30b98.tar.xz nano-exporter-f771790b633f02f3857689e9848b0756aeb30b98.zip |
Bugfix: cbuf_cmp handled prefixes incorrectly.
The previous version returned 0 if the string to compare was either equal to or a prefix of the target buffer. This change fixes it to only return 0 when the string is actually equal. Otherwise, it follows the shortlex ordering, for convenience.
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/util.c b/util.c index e88ef95..643487b 100644 --- a/util.c +++ b/util.c @@ -93,7 +93,13 @@ const char *cbuf_get(struct cbuf *buf, size_t *len) { } int cbuf_cmp(cbuf *buf, const char *other) { - return strncmp(buf->data, other, buf->len); + size_t other_len = strlen(other); + if (buf->len < other_len) + return -1; + else if (buf->len == other_len) + return memcmp(buf->data, other, buf->len); + else + return +1; } // string lists |