Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
158a6ab2
Commit
158a6ab2
authored
8 years ago
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
8 years ago
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3367 from ksss/str-modify
Fix segv on str_buf_cat
parents
07167b8f
8a9a2415
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
9 deletions
+13
-9
src/string.c
src/string.c
+13
-9
No files found.
src/string.c
View file @
158a6ab2
...
...
@@ -154,10 +154,7 @@ str_buf_cat(mrb_state *mrb, struct RString *s, const char *ptr, size_t len)
off
=
ptr
-
RSTR_PTR
(
s
);
}
if
(
RSTR_EMBED_P
(
s
))
capa
=
RSTRING_EMBED_LEN_MAX
;
else
capa
=
s
->
as
.
heap
.
aux
.
capa
;
capa
=
RSTR_CAPA
(
s
);
if
(
capa
<=
RSTRING_EMBED_LEN_MAX
)
capa
=
RSTRING_EMBED_LEN_MAX
+
1
;
...
...
@@ -698,14 +695,21 @@ mrb_str_modify(mrb_state *mrb, struct RString *s)
}
if
(
RSTR_NOFREE_P
(
s
))
{
char
*
p
=
s
->
as
.
heap
.
ptr
;
mrb_int
len
=
s
->
as
.
heap
.
len
;
s
->
as
.
heap
.
ptr
=
(
char
*
)
mrb_malloc
(
mrb
,
(
size_t
)
s
->
as
.
heap
.
len
+
1
);
RSTR_UNSET_NOFREE_FLAG
(
s
);
if
(
len
<
RSTRING_EMBED_LEN_MAX
)
{
RSTR_SET_EMBED_FLAG
(
s
);
RSTR_SET_EMBED_LEN
(
s
,
len
);
}
else
{
s
->
as
.
heap
.
ptr
=
(
char
*
)
mrb_malloc
(
mrb
,
(
size_t
)
len
+
1
);
s
->
as
.
heap
.
aux
.
capa
=
len
;
}
if
(
p
)
{
memcpy
(
RSTR_PTR
(
s
),
p
,
s
->
as
.
heap
.
len
);
memcpy
(
RSTR_PTR
(
s
),
p
,
len
);
}
RSTR_PTR
(
s
)[
s
->
as
.
heap
.
len
]
=
'\0'
;
s
->
as
.
heap
.
aux
.
capa
=
s
->
as
.
heap
.
len
;
RSTR_UNSET_NOFREE_FLAG
(
s
);
RSTR_PTR
(
s
)[
len
]
=
'\0'
;
return
;
}
}
...
...
This diff is collapsed.
Click to expand it.
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