Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
openfoam
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
openfoam
Commits
a43b7a91
Commit
a43b7a91
authored
16 years ago
by
Mark Olesen
Browse files
Options
Downloads
Patches
Plain Diff
handle NULL pointer in regExp
parent
239c31f3
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
applications/test/regex/Make/options
+0
-3
0 additions, 3 deletions
applications/test/regex/Make/options
applications/test/regex/regexTest.C
+30
-0
30 additions, 0 deletions
applications/test/regex/regexTest.C
src/OSspecific/Unix/regExp.C
+20
-8
20 additions, 8 deletions
src/OSspecific/Unix/regExp.C
with
50 additions
and
11 deletions
applications/test/regex/Make/options
+
0
−
3
View file @
a43b7a91
EXE_LIBS = \
$(FOAM_LIBBIN)/libOSspecific.o
This diff is collapsed.
Click to expand it.
applications/test/regex/regexTest.C
+
30
−
0
View file @
a43b7a91
...
...
@@ -76,6 +76,36 @@ int main(int argc, char *argv[])
Info
<<
endl
;
}
Info
<<
"test regExp(const char*) ..."
<<
endl
;
string
me
(
"Mark"
);
if
(
regExp
(
"[Mm]ar[ck]"
).
match
(
me
))
{
Info
<<
"matched: "
<<
me
<<
endl
;
}
else
{
Info
<<
"no match"
<<
endl
;
}
if
(
regExp
(
""
).
match
(
me
))
{
Info
<<
"matched: "
<<
me
<<
endl
;
}
else
{
Info
<<
"no match"
<<
endl
;
}
if
(
regExp
(
NULL
).
match
(
me
))
{
Info
<<
"matched: "
<<
me
<<
endl
;
}
else
{
Info
<<
"no match"
<<
endl
;
}
Info
<<
endl
;
return
0
;
...
...
This diff is collapsed.
Click to expand it.
src/OSspecific/Unix/regExp.C
+
20
−
8
View file @
a43b7a91
...
...
@@ -37,15 +37,20 @@ License
void
Foam
::
regExp
::
compile
(
const
char
*
pat
)
const
{
clear
();
preg_
=
new
regex_t
;
if
(
regcomp
(
preg_
,
pat
,
REG_EXTENDED
)
!=
0
)
// avoid NULL and zero-length patterns
if
(
pat
&&
*
pat
)
{
FatalErrorIn
(
"regExp::compile(const char*)"
)
<<
"Failed to compile regular expression '"
<<
pat
<<
"'"
<<
exit
(
FatalError
);
preg_
=
new
regex_t
;
if
(
regcomp
(
preg_
,
pat
,
REG_EXTENDED
)
!=
0
)
{
FatalErrorIn
(
"regExp::compile(const char*)"
)
<<
"Failed to compile regular expression '"
<<
pat
<<
"'"
<<
exit
(
FatalError
);
}
}
}
...
...
@@ -60,6 +65,7 @@ void Foam::regExp::clear() const
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam
::
regExp
::
regExp
()
...
...
@@ -83,6 +89,7 @@ Foam::regExp::regExp(const char* pat)
compile
(
pat
);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam
::
regExp
::~
regExp
()
...
...
@@ -90,6 +97,7 @@ Foam::regExp::~regExp()
clear
();
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
int
Foam
::
regExp
::
ngroups
()
const
...
...
@@ -110,6 +118,7 @@ bool Foam::regExp::match
regmatch_t
pmatch
[
1
];
// match and also verify that the entire string was matched
// pmatch[0] is the entire match
if
(
regexec
(
preg_
,
str
.
c_str
(),
nmatch
,
pmatch
,
0
)
==
0
...
...
@@ -141,6 +150,8 @@ bool Foam::regExp::match
regmatch_t
pmatch
[
nmatch
];
// match and also verify that the entire string was matched
// pmatch[0] is the entire match
// pmatch[1..] are the (...) sub-groups
if
(
regexec
(
preg_
,
str
.
c_str
(),
nmatch
,
pmatch
,
0
)
==
0
...
...
@@ -179,8 +190,8 @@ bool Foam::regExp::match
return
false
;
}
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
void
Foam
::
regExp
::
operator
=
(
const
string
&
pat
)
{
...
...
@@ -193,4 +204,5 @@ void Foam::regExp::operator=(const char* pat)
compile
(
pat
);
}
// ************************************************************************* //
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment