]> git.sur5r.net Git - openldap/blobdiff - libraries/librewrite/subst.c
Fix up abandon merge. Hallvard will holler if I get this wrong. :-)
[openldap] / libraries / librewrite / subst.c
index df0414aca32b21ff92519bea6cb70c13fd24735a..4c0bc411e0fa627c0d77084e2a116da33c635f06 100644 (file)
@@ -36,7 +36,7 @@ rewrite_subst_compile(
 )
 {
        size_t subs_len;
-       struct berval **subs = NULL;
+       struct berval **subs = NULL, **tmps;
        struct rewrite_submatch **submatch = NULL;
 
        struct rewrite_subst *s = NULL;
@@ -53,24 +53,25 @@ rewrite_subst_compile(
        for ( p = begin = result, subs_len = 0; p[ 0 ] != '\0'; p++ ) {
                
                /*
-                * Keep only single escapes '\'
+                * Keep only single escapes '%'
                 */
                if ( p[ 0 ] != REWRITE_SUBMATCH_ESCAPE ) {
                        continue;
                } 
                if ( p[ 1 ] == REWRITE_SUBMATCH_ESCAPE ) {
-                       memmove((char *)p, p + 1, strlen( p ) );
+                       AC_MEMCPY((char *)p, p + 1, strlen( p ) );
                        continue;
                }
 
                nsub++;
                
-               subs = (struct berval **)realloc( subs,
+               tmps = (struct berval **)realloc( subs,
                                sizeof( struct berval * )*( nsub + 1 ) );
-               if ( subs == NULL ) {
+               if ( tmps == NULL ) {
                        /* cleanup */
                        return NULL;
                }
+               subs = tmps;
                subs[ nsub ] = NULL;
                
                /*
@@ -100,19 +101,22 @@ rewrite_subst_compile(
                /*
                 * Substitution pattern
                 */
-               if ( isdigit( p[ 1 ] ) ) {
+               if ( isdigit( (unsigned char) p[ 1 ] ) ) {
                        int d = p[ 1 ] - '0';
+                       struct rewrite_submatch **tmpsm;
 
                        /*
                         * Add a new value substitution scheme
                         */
-                       submatch = realloc( submatch, 
+                       tmpsm = realloc( submatch, 
        sizeof( struct rewrite_submatch * )*( nsub + 1 ) );
-                       if ( submatch == NULL ) {
+                       if ( tmpsm == NULL ) {
                                /* cleanup */
                                return NULL;
                        }
+                       submatch = tmpsm;
                        submatch[ nsub ] = NULL;
+                       
                        submatch[ nsub - 1 ] = 
        calloc( sizeof(  struct rewrite_submatch ), 1 );
                        if ( submatch[ nsub - 1 ] == NULL ) {
@@ -151,6 +155,7 @@ rewrite_subst_compile(
                 */
                } else if ( p[ 1 ] == '{' ) {
                        struct rewrite_map *map;
+                       struct rewrite_submatch **tmpsm;
 
                        map = rewrite_map_parse( info, p + 2, &begin );
                        if ( map == NULL ) {
@@ -162,12 +167,13 @@ rewrite_subst_compile(
                        /*
                         * Add a new value substitution scheme
                         */
-                       submatch = realloc( submatch,
+                       tmpsm = realloc( submatch,
                                        sizeof( struct rewrite_submatch * )*( nsub + 1 ) );
-                       if ( submatch == NULL ) {
+                       if ( tmpsm == NULL ) {
                                /* cleanup */
                                return NULL;
                        }
+                       submatch = tmpsm;
                        submatch[ nsub ] = NULL;
                        submatch[ nsub - 1 ] =
                                calloc( sizeof(  struct rewrite_submatch ), 1 );
@@ -186,15 +192,16 @@ rewrite_subst_compile(
        /*
         * Last part of string
         */
-       subs = realloc( subs, sizeof( struct berval *)*( nsub + 2 ) );
-       if ( subs == NULL ) {
+       tmps = realloc( subs, sizeof( struct berval *)*( nsub + 2 ) );
+       if ( tmps == NULL ) {
                /*
                 * XXX need to free the value subst stuff!
                 */
                free( submatch );
                return NULL;
        }
-       
+
+       subs = tmps;
        subs[ nsub + 1 ] = NULL;
        l = p - begin;
        if ( l > 0 ) {