From bc6739419e1c9fc893cc6ede7bfa3d464e0bcaad Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Malo?= Date: Sun, 3 Aug 2003 20:15:50 +0000 Subject: [PATCH] cleanup compare_lexicography function. - improve readability - make sure that unsigned chars are compared - use apr_size_t for string lengths git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@100895 13f79535-47bb-0310-9956-ffa450edef68 --- modules/mappers/mod_rewrite.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index a194e93107..7ef7e78eb3 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -3216,28 +3216,24 @@ static const char *cmd_rewriterule(cmd_parms *cmd, void *in_dconf, */ /* Lexicographic Compare */ -static APR_INLINE int compare_lexicography(char *cpNum1, char *cpNum2) +static APR_INLINE int compare_lexicography(char *a, char *b) { - int i; - int n1, n2; + apr_size_t i, lena, lenb; - n1 = strlen(cpNum1); - n2 = strlen(cpNum2); - if (n1 > n2) { - return 1; - } - if (n1 < n2) { - return -1; - } - for (i = 0; i < n1; i++) { - if (cpNum1[i] > cpNum2[i]) { - return 1; - } - if (cpNum1[i] < cpNum2[i]) { - return -1; + lena = strlen(a); + lenb = strlen(b); + + if (lena == lenb) { + for (i = 0; i < lena; ++i) { + if (a[i] != b[i]) { + return ((unsigned char)a[i] > (unsigned char)b[i]) ? 1 : -1; + } } + + return 0; } - return 0; + + return ((lena > lenb) ? 1 : -1); } /* -- 2.50.1