Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
c8e75cdc
Commit
c8e75cdc
authored
Jun 23, 2014
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tal/str: fix error when strreg regex looks for literal slashes.
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
58c5a352
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
2 deletions
+28
-2
ccan/tal/str/str.c
ccan/tal/str/str.c
+23
-1
ccan/tal/str/test/run-strreg.c
ccan/tal/str/test/run-strreg.c
+5
-1
No files found.
ccan/tal/str/str.c
View file @
c8e75cdc
...
...
@@ -236,9 +236,31 @@ fail:
goto
out
;
}
static
size_t
count_open_braces
(
const
char
*
string
)
{
#if 1
size_t
num
=
0
,
esc
=
0
;
while
(
*
string
)
{
if
(
*
string
==
'\\'
)
esc
++
;
else
{
/* An odd number of \ means it's escaped. */
if
(
*
string
==
'('
&&
(
esc
&
1
)
==
0
)
num
++
;
esc
=
0
;
}
string
++
;
}
return
num
;
#else
return
strcount
(
string
,
"("
);
#endif
}
bool
tal_strreg
(
const
tal_t
*
ctx
,
const
char
*
string
,
const
char
*
regex
,
...)
{
size_t
nmatch
=
1
+
strcount
(
regex
,
"("
);
size_t
nmatch
=
1
+
count_open_braces
(
regex
);
regmatch_t
matches
[
nmatch
];
regex_t
r
;
bool
ret
=
false
;
...
...
ccan/tal/str/test/run-strreg.c
View file @
c8e75cdc
...
...
@@ -21,7 +21,7 @@ int main(int argc, char *argv[])
/* If it accesses this, it will crash. */
char
**
invalid
=
(
char
**
)
1L
;
plan_tests
(
4
0
);
plan_tests
(
4
1
);
/* Simple matching. */
ok1
(
tal_strreg
(
ctx
,
"hello world!"
,
"hello"
)
==
true
);
ok1
(
tal_strreg
(
ctx
,
"hello world!"
,
"hi"
)
==
false
);
...
...
@@ -116,5 +116,9 @@ int main(int argc, char *argv[])
ok1
(
no_children
(
ctx
));
tal_free
(
ctx
);
/* Don't get fooled by \(! */
ok1
(
tal_strreg
(
ctx
,
"(hello) (world)!"
,
"
\\
([a-z]*
\\
)
\\
([a-z]+
\\
)"
,
invalid
)
==
true
);
return
exit_status
();
}
Write
Preview
Markdown
is supported
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