diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2024-05-08 09:30:20 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2024-05-08 09:30:20 +0200 |
commit | 9f536d3dc7500611819d3180d5794c787c06e469 (patch) | |
tree | cfae7c5c648af7b11f95e2f47a3a569f35f39ce6 /src/core/core-string.c | |
parent | 4d0458afdd0329d0329ef4ec7e8ae7ec1aa6ee40 (diff) | |
download | weechat-9f536d3dc7500611819d3180d5794c787c06e469.zip |
api: return `-1` or `1` if one input string is NULL and not the other in string comparison functions
Diffstat (limited to 'src/core/core-string.c')
-rw-r--r-- | src/core/core-string.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/core/core-string.c b/src/core/core-string.c index 8e9917b96..2c46e1d33 100644 --- a/src/core/core-string.c +++ b/src/core/core-string.c @@ -621,6 +621,12 @@ string_strcmp (const char *string1, const char *string2) { int diff; + if (!string1 && string2) + return -1; + + if (string1 && !string2) + return 1; + while (string1 && string1[0] && string2 && string2[0]) { diff = string_charcmp (string1, string2); @@ -649,6 +655,12 @@ string_strncmp (const char *string1, const char *string2, int max) { int count, diff; + if (!string1 && string2) + return -1; + + if (string1 && !string2) + return 1; + count = 0; while ((count < max) && string1 && string1[0] && string2 && string2[0]) { @@ -683,6 +695,12 @@ string_strcasecmp (const char *string1, const char *string2) { int diff; + if (!string1 && string2) + return -1; + + if (string1 && !string2) + return 1; + while (string1 && string1[0] && string2 && string2[0]) { diff = string_charcasecmp (string1, string2); @@ -721,6 +739,12 @@ string_strcasecmp_range (const char *string1, const char *string2, int range) { int diff; + if (!string1 && string2) + return -1; + + if (string1 && !string2) + return 1; + while (string1 && string1[0] && string2 && string2[0]) { diff = string_charcasecmp_range (string1, string2, range); @@ -750,6 +774,12 @@ string_strncasecmp (const char *string1, const char *string2, int max) { int count, diff; + if (!string1 && string2) + return -1; + + if (string1 && !string2) + return 1; + count = 0; while ((count < max) && string1 && string1[0] && string2 && string2[0]) { @@ -794,6 +824,12 @@ string_strncasecmp_range (const char *string1, const char *string2, int max, { int count, diff; + if (!string1 && string2) + return -1; + + if (string1 && !string2) + return 1; + count = 0; while ((count < max) && string1 && string1[0] && string2 && string2[0]) { @@ -830,6 +866,12 @@ string_strcmp_ignore_chars (const char *string1, const char *string2, { int diff; + if (!string1 && string2) + return -1; + + if (string1 && !string2) + return 1; + while (string1 && string1[0] && string2 && string2[0]) { /* skip ignored chars */ |