Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Robert Dubner
OpenLDAP
Commits
666f201c
Commit
666f201c
authored
Oct 22, 2001
by
Pierangelo Masarati
Browse files
more elegant use of realloc; still needs cleanup in case of error
parent
03a97678
Changes
1
Hide whitespace changes
Inline
Side-by-side
libraries/librewrite/subst.c
View file @
666f201c
...
...
@@ -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
;
...
...
@@ -65,12 +65,13 @@ rewrite_subst_compile(
nsub
++
;
sub
s
=
(
struct
berval
**
)
realloc
(
subs
,
tmp
s
=
(
struct
berval
**
)
realloc
(
subs
,
sizeof
(
struct
berval
*
)
*
(
nsub
+
1
)
);
if
(
sub
s
==
NULL
)
{
if
(
tmp
s
==
NULL
)
{
/* cleanup */
return
NULL
;
}
subs
=
tmps
;
subs
[
nsub
]
=
NULL
;
/*
...
...
@@ -102,17 +103,20 @@ rewrite_subst_compile(
*/
if
(
isdigit
(
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
*/
sub
s
=
realloc
(
subs
,
sizeof
(
struct
berval
*
)
*
(
nsub
+
2
)
);
if
(
sub
s
==
NULL
)
{
tmp
s
=
realloc
(
subs
,
sizeof
(
struct
berval
*
)
*
(
nsub
+
2
)
);
if
(
tmp
s
==
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
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment