apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bri...@apache.org
Subject cvs commit: apr-util/test teststrmatch.c
Date Fri, 24 May 2002 14:33:22 GMT
brianp      02/05/24 07:33:22

  Modified:    strmatch apr_strmatch.c
               test     teststrmatch.c
  Log:
  Updated the unsigned character handling in apr_strmatch()
  for better portability
  
  Revision  Changes    Path
  1.4       +14 -14    apr-util/strmatch/apr_strmatch.c
  
  Index: apr_strmatch.c
  ===================================================================
  RCS file: /home/cvs/apr-util/strmatch/apr_strmatch.c,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- apr_strmatch.c	24 May 2002 01:07:47 -0000	1.3
  +++ apr_strmatch.c	24 May 2002 14:33:22 -0000	1.4
  @@ -110,14 +110,14 @@
   
   APU_DECLARE_NONSTD(const char *) match_boyer_moore_horspool(const apr_strmatch_pattern
*this_pattern, const char *s, apr_size_t slen)
   {
  -    const unsigned char *s_end = s + slen;
  +    const char *s_end = s + slen;
       int *shift = (int *)(this_pattern->context);
  -    const unsigned char *s_next = s + this_pattern->length - 1;
  -    const unsigned char *p_start = this_pattern->pattern;
  -    const unsigned char *p_end = p_start + this_pattern->length - 1;
  +    const char *s_next = s + this_pattern->length - 1;
  +    const char *p_start = this_pattern->pattern;
  +    const char *p_end = p_start + this_pattern->length - 1;
       while (s_next < s_end) {
  -        const unsigned char *s_tmp = s_next;
  -        const unsigned char *p_tmp = p_end;
  +        const char *s_tmp = s_next;
  +        const char *p_tmp = p_end;
           while (*s_tmp == *p_tmp) {
               p_tmp--;
               if (p_tmp < p_start) {
  @@ -125,21 +125,21 @@
               }
               s_tmp--;
           }
  -        s_next += shift[(int)*s_next];
  +        s_next += shift[(int)*((const unsigned char *)s_next)];
       }
       return NULL;
   }
   
   APU_DECLARE_NONSTD(const char *) match_boyer_moore_horspool_nocase(const apr_strmatch_pattern
*this_pattern, const char *s, apr_size_t slen)
   {
  -    const unsigned char *s_end = s + slen;
  +    const char *s_end = s + slen;
       int *shift = (int *)(this_pattern->context);
  -    const unsigned char *s_next = s + this_pattern->length - 1;
  -    const unsigned char *p_start = this_pattern->pattern;
  -    const unsigned char *p_end = p_start + this_pattern->length - 1;
  +    const char *s_next = s + this_pattern->length - 1;
  +    const char *p_start = this_pattern->pattern;
  +    const char *p_end = p_start + this_pattern->length - 1;
       while (s_next < s_end) {
  -        const unsigned char *s_tmp = s_next;
  -        const unsigned char *p_tmp = p_end;
  +        const char *s_tmp = s_next;
  +        const char *p_tmp = p_end;
           while (apr_tolower(*s_tmp) == apr_tolower(*p_tmp)) {
               p_tmp--;
               if (p_tmp < p_start) {
  @@ -147,7 +147,7 @@
               }
               s_tmp--;
           }
  -        s_next += shift[(int)*s_next];
  +        s_next += shift[(int)*((const unsigned char *)s_next)];
       }
       return NULL;
   }
  
  
  
  1.3       +16 -0     apr-util/test/teststrmatch.c
  
  Index: teststrmatch.c
  ===================================================================
  RCS file: /home/cvs/apr-util/test/teststrmatch.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- teststrmatch.c	9 May 2002 17:00:25 -0000	1.2
  +++ teststrmatch.c	24 May 2002 14:33:22 -0000	1.3
  @@ -75,6 +75,8 @@
       const char *input2 = "string that contains a pattern...";
       const char *input3 = "pattern at the start of a string";
       const char *input4 = "string that ends with a pattern";
  +    const char *input5 = "patter\200n not found, negative chars in input";
  +    const char *input6 = "patter\200n, negative chars, contains pattern...";
   
       (void) apr_initialize();
       apr_pool_create(&pool, NULL);
  @@ -146,6 +148,20 @@
   
       printf("testing match at end of string...");
       if (apr_strmatch(pattern, input4, strlen(input4)) != input4 + 24) {
  +        printf("FAILED\n");
  +        exit(1);
  +    }
  +    printf("OK\n");
  +
  +    printf("testing invalid match with negative chars in intput string...");
  +    if (apr_strmatch(pattern, input5, strlen(input5)) != NULL) {
  +        printf("FAILED\n");
  +        exit(1);
  +    }
  +    printf("OK\n");
  +
  +    printf("testing valid match with negative chars in intput string...");
  +    if (apr_strmatch(pattern, input6, strlen(input6)) != input6 + 35) {
           printf("FAILED\n");
           exit(1);
       }
  
  
  

Mime
View raw message