Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Alchemy Viewer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Silent mode is enabled
All outbound communications are blocked.
Learn more
.
Show more breadcrumbs
Alchemy Viewer
Alchemy Viewer
Commits
9a7e638b
Commit
9a7e638b
authored
2 years ago
by
Nat Goodspeed
Browse files
Options
Downloads
Patches
Plain Diff
DRTVWR-575: Defend unescape_string() against empty line.
The unsigned index arithmetic was problematic in that case.
parent
db1d757a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
indra/llcommon/llstreamtools.cpp
+7
-17
7 additions, 17 deletions
indra/llcommon/llstreamtools.cpp
with
7 additions
and
17 deletions
indra/llcommon/llstreamtools.cpp
+
7
−
17
View file @
9a7e638b
...
@@ -331,8 +331,7 @@ bool remove_last_char(char c, std::string& line)
...
@@ -331,8 +331,7 @@ bool remove_last_char(char c, std::string& line)
void
unescape_string
(
std
::
string
&
line
)
void
unescape_string
(
std
::
string
&
line
)
{
{
auto
line_size
=
line
.
size
();
auto
line_size
=
line
.
size
();
size_t
index
=
0
;
for
(
size_t
index
=
0
;
line_size
>=
1
&&
index
<
line_size
-
1
;
++
index
)
while
(
index
<
line_size
-
1
)
{
{
if
(
'\\'
==
line
[
index
])
if
(
'\\'
==
line
[
index
])
{
{
...
@@ -347,7 +346,6 @@ void unescape_string(std::string& line)
...
@@ -347,7 +346,6 @@ void unescape_string(std::string& line)
line_size
--
;
line_size
--
;
}
}
}
}
index
++
;
}
}
}
}
...
@@ -357,8 +355,7 @@ void unescape_string(std::string& line)
...
@@ -357,8 +355,7 @@ void unescape_string(std::string& line)
void
escape_string
(
std
::
string
&
line
)
void
escape_string
(
std
::
string
&
line
)
{
{
auto
line_size
=
line
.
size
();
auto
line_size
=
line
.
size
();
size_t
index
=
0
;
for
(
size_t
index
=
0
;
index
<
line_size
;
++
index
)
while
(
index
<
line_size
)
{
{
if
(
'\\'
==
line
[
index
])
if
(
'\\'
==
line
[
index
])
{
{
...
@@ -372,7 +369,6 @@ void escape_string(std::string& line)
...
@@ -372,7 +369,6 @@ void escape_string(std::string& line)
line_size
++
;
line_size
++
;
index
++
;
index
++
;
}
}
index
++
;
}
}
}
}
...
@@ -380,23 +376,20 @@ void escape_string(std::string& line)
...
@@ -380,23 +376,20 @@ void escape_string(std::string& line)
void
replace_newlines_with_whitespace
(
std
::
string
&
line
)
void
replace_newlines_with_whitespace
(
std
::
string
&
line
)
{
{
auto
line_size
=
line
.
size
();
auto
line_size
=
line
.
size
();
size_t
index
=
0
;
for
(
size_t
index
=
0
;
index
<
line_size
;
++
index
)
while
(
index
<
line_size
)
{
{
if
(
'\n'
==
line
[
index
])
if
(
'\n'
==
line
[
index
])
{
{
line
.
replace
(
index
,
1
,
" "
);
line
.
replace
(
index
,
1
,
" "
);
}
}
index
++
;
}
}
}
}
// erases any double-quote characters in 'line'
// erases any double-quote characters in 'line'
void
remove_double_quotes
(
std
::
string
&
line
)
void
remove_double_quotes
(
std
::
string
&
line
)
{
{
size_t
index
=
0
;
auto
line_size
=
line
.
size
();
auto
line_size
=
line
.
size
();
while
(
index
<
line_size
)
for
(
size_t
index
=
0
;
index
<
line_size
;
)
{
{
if
(
'"'
==
line
[
index
])
if
(
'"'
==
line
[
index
])
{
{
...
@@ -427,19 +420,18 @@ void get_keyword_and_value(std::string& keyword,
...
@@ -427,19 +420,18 @@ void get_keyword_and_value(std::string& keyword,
auto
line_size
=
line
.
size
();
auto
line_size
=
line
.
size
();
size_t
line_index
=
0
;
size_t
line_index
=
0
;
char
c
;
char
c
;
while
(
line_index
<
line_size
)
for
(
;
line_index
<
line_size
;
++
line_index
)
{
{
c
=
line
[
line_index
];
c
=
line
[
line_index
];
if
(
!
LLStringOps
::
isSpace
(
c
))
if
(
!
LLStringOps
::
isSpace
(
c
))
{
{
break
;
break
;
}
}
line_index
++
;
}
}
// get the keyword
// get the keyword
keyword
.
clear
();
keyword
.
clear
();
while
(
line_index
<
line_size
)
for
(
;
line_index
<
line_size
;
++
line_index
)
{
{
c
=
line
[
line_index
];
c
=
line
[
line_index
];
if
(
LLStringOps
::
isSpace
(
c
)
||
'\r'
==
c
||
'\n'
==
c
)
if
(
LLStringOps
::
isSpace
(
c
)
||
'\r'
==
c
||
'\n'
==
c
)
...
@@ -447,7 +439,6 @@ void get_keyword_and_value(std::string& keyword,
...
@@ -447,7 +439,6 @@ void get_keyword_and_value(std::string& keyword,
break
;
break
;
}
}
keyword
+=
c
;
keyword
+=
c
;
line_index
++
;
}
}
// get the value
// get the value
...
@@ -465,7 +456,7 @@ void get_keyword_and_value(std::string& keyword,
...
@@ -465,7 +456,7 @@ void get_keyword_and_value(std::string& keyword,
line_index
++
;
line_index
++
;
}
}
while
(
line_index
<
line_size
)
for
(
;
line_index
<
line_size
;
++
line_index
)
{
{
c
=
line
[
line_index
];
c
=
line
[
line_index
];
if
(
'\r'
==
c
||
'\n'
==
c
)
if
(
'\r'
==
c
||
'\n'
==
c
)
...
@@ -473,7 +464,6 @@ void get_keyword_and_value(std::string& keyword,
...
@@ -473,7 +464,6 @@ void get_keyword_and_value(std::string& keyword,
break
;
break
;
}
}
value
+=
c
;
value
+=
c
;
line_index
++
;
}
}
}
}
}
}
...
...
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