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
3b2b760e
Commit
3b2b760e
authored
Aug 07, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1445 from cremno/no_strcpy_and_strcat
don't use str{cpy,cat} in mruby and mrbc
parents
d2be1542
29381bc8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
14 deletions
+34
-14
mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
+13
-5
src/parse.y
src/parse.y
+13
-5
tools/mrbc/mrbc.c
tools/mrbc/mrbc.c
+8
-4
No files found.
mrbgems/mruby-bin-mruby/tools/mruby/mruby.c
View file @
3b2b760e
...
...
@@ -91,16 +91,24 @@ parse_args(mrb_state *mrb, int argc, char **argv, struct _args *args)
item
=
argv
[
0
];
append_cmdline:
if
(
!
args
->
cmdline
)
{
size_t
buflen
;
char
*
buf
;
buf
=
(
char
*
)
mrb_malloc
(
mrb
,
strlen
(
item
)
+
1
);
strcpy
(
buf
,
item
);
buflen
=
strlen
(
item
)
+
1
;
buf
=
(
char
*
)
mrb_malloc
(
mrb
,
buflen
);
memcpy
(
buf
,
item
,
buflen
);
args
->
cmdline
=
buf
;
}
else
{
args
->
cmdline
=
(
char
*
)
mrb_realloc
(
mrb
,
args
->
cmdline
,
strlen
(
args
->
cmdline
)
+
strlen
(
item
)
+
2
);
strcat
(
args
->
cmdline
,
"
\n
"
);
strcat
(
args
->
cmdline
,
item
);
size_t
cmdlinelen
;
size_t
itemlen
;
cmdlinelen
=
strlen
(
args
->
cmdline
);
itemlen
=
strlen
(
item
);
args
->
cmdline
=
(
char
*
)
mrb_realloc
(
mrb
,
args
->
cmdline
,
cmdlinelen
+
itemlen
+
2
);
args
->
cmdline
[
cmdlinelen
]
=
'\n'
;
memcpy
(
args
->
cmdline
+
cmdlinelen
+
1
,
item
,
itemlen
+
1
);
}
}
else
{
...
...
src/parse.y
View file @
3b2b760e
...
...
@@ -3701,7 +3701,9 @@ parse_string(parser_state *p)
int f = 0;
int c;
char *s = strndup(tok(p), toklen(p));
char flag[4] = { '\0' };
char flags[3];
char *flag = flags;
char *dup;
newtok(p);
while (c = nextc(p), c != -1 && ISALPHA(c)) {
...
...
@@ -3720,10 +3722,16 @@ parse_string(parser_state *p)
toklen(p) > 1 ? "s" : "", tok(p));
yyerror(p, msg);
}
if (f & 1) strcat(flag, "i");
if (f & 2) strcat(flag, "x");
if (f & 4) strcat(flag, "m");
yylval.nd = new_regx(p, s, strdup(flag));
if (f != 0) {
if (f & 1) *flag++ = 'i';
if (f & 2) *flag++ = 'x';
if (f & 4) *flag++ = 'm';
dup = strndup(flags, (size_t)(flag - flags));
}
else {
dup = NULL;
}
yylval.nd = new_regx(p, s, dup);
return tREGEXP;
}
...
...
tools/mrbc/mrbc.c
View file @
3b2b760e
...
...
@@ -51,15 +51,19 @@ usage(const char *name)
static
char
*
get_outfilename
(
mrb_state
*
mrb
,
char
*
infile
,
char
*
ext
)
{
size_t
infilelen
;
size_t
extlen
;
char
*
outfile
;
char
*
p
;
outfile
=
(
char
*
)
mrb_malloc
(
mrb
,
strlen
(
infile
)
+
strlen
(
ext
)
+
1
);
strcpy
(
outfile
,
infile
);
infilelen
=
strlen
(
infile
);
extlen
=
strlen
(
ext
);
outfile
=
(
char
*
)
mrb_malloc
(
mrb
,
infilelen
+
extlen
+
1
);
memcpy
(
outfile
,
infile
,
infilelen
+
1
);
if
(
*
ext
)
{
if
((
p
=
strrchr
(
outfile
,
'.'
))
==
NULL
)
p
=
&
outfile
[
strlen
(
outfile
)]
;
strcpy
(
p
,
ext
);
p
=
outfile
+
infilelen
;
memcpy
(
p
,
ext
,
extlen
+
1
);
}
return
outfile
;
...
...
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