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
7c64a2be
Commit
7c64a2be
authored
Jun 26, 2012
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #329 from monaka/pr-reduce-magic-number-in-snprintf
Use sizeof to get char array sizes.
parents
cf8b6ec8
2042684b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
15 additions
and
15 deletions
+15
-15
src/class.c
src/class.c
+2
-2
src/codegen.c
src/codegen.c
+2
-2
src/error.c
src/error.c
+3
-3
src/parse.y
src/parse.y
+4
-4
src/time.c
src/time.c
+1
-1
src/vm.c
src/vm.c
+3
-3
No files found.
src/class.c
View file @
7c64a2be
...
...
@@ -1149,11 +1149,11 @@ mrb_mod_to_s(mrb_state *mrb, mrb_value klass)
switch
(
mrb_type
(
klass
))
{
case
MRB_TT_CLASS
:
snprintf
(
buf
,
256
,
"#<Class:%p>"
,
c
);
snprintf
(
buf
,
sizeof
(
buf
)
,
"#<Class:%p>"
,
c
);
break
;
case
MRB_TT_MODULE
:
snprintf
(
buf
,
256
,
"#<Module:%p>"
,
c
);
snprintf
(
buf
,
sizeof
(
buf
)
,
"#<Module:%p>"
,
c
);
break
;
default:
...
...
src/codegen.c
View file @
7c64a2be
...
...
@@ -1537,7 +1537,7 @@ codegen(codegen_scope *s, node *tree, int val)
int
len
;
int
sym
;
len
=
snprintf
(
buf
,
3
,
"$%c"
,
(
int
)(
intptr_t
)
tree
);
len
=
snprintf
(
buf
,
sizeof
(
buf
)
,
"$%c"
,
(
int
)(
intptr_t
)
tree
);
sym
=
new_sym
(
s
,
mrb_intern2
(
s
->
mrb
,
buf
,
len
));
genop
(
s
,
MKOP_ABx
(
OP_GETGLOBAL
,
cursp
(),
sym
));
push
();
...
...
@@ -1550,7 +1550,7 @@ codegen(codegen_scope *s, node *tree, int val)
int
len
;
int
sym
;
len
=
snprintf
(
buf
,
3
,
"$%d"
,
(
int
)(
intptr_t
)
tree
);
len
=
snprintf
(
buf
,
sizeof
(
buf
)
,
"$%d"
,
(
int
)(
intptr_t
)
tree
);
sym
=
new_sym
(
s
,
mrb_intern2
(
s
->
mrb
,
buf
,
len
));
genop
(
s
,
MKOP_ABx
(
OP_GETGLOBAL
,
cursp
(),
sym
));
push
();
...
...
src/error.c
View file @
7c64a2be
...
...
@@ -180,7 +180,7 @@ mrb_raise(mrb_state *mrb, struct RClass *c, const char *fmt, ...)
int
n
;
va_start
(
args
,
fmt
);
n
=
vsnprintf
(
buf
,
256
,
fmt
,
args
);
n
=
vsnprintf
(
buf
,
sizeof
(
buf
)
,
fmt
,
args
);
va_end
(
args
);
if
(
n
<
0
)
{
n
=
0
;
...
...
@@ -197,7 +197,7 @@ mrb_name_error(mrb_state *mrb, mrb_sym id, const char *fmt, ...)
int
n
;
va_start
(
args
,
fmt
);
n
=
vsnprintf
(
buf
,
256
,
fmt
,
args
);
n
=
vsnprintf
(
buf
,
sizeof
(
buf
)
,
fmt
,
args
);
va_end
(
args
);
if
(
n
<
0
)
{
n
=
0
;
...
...
@@ -216,7 +216,7 @@ mrb_sprintf(mrb_state *mrb, const char *fmt, ...)
int
n
;
va_start
(
args
,
fmt
);
n
=
vsnprintf
(
buf
,
256
,
fmt
,
args
);
n
=
vsnprintf
(
buf
,
sizeof
(
buf
)
,
fmt
,
args
);
va_end
(
args
);
if
(
n
<
0
)
{
n
=
0
;
...
...
src/parse.y
View file @
7c64a2be
...
...
@@ -2587,7 +2587,7 @@ var_ref : variable
{
char buf[16];
snprintf(buf,
16
, "%d", p->lineno);
snprintf(buf,
sizeof(buf)
, "%d", p->lineno);
$$ = new_int(p, buf, 10);
}
;
...
...
@@ -2955,7 +2955,7 @@ yyerror_i(parser_state *p, const char *fmt, int i)
{
char buf[256];
snprintf(buf,
256
, fmt, i);
snprintf(buf,
sizeof(buf)
, fmt, i);
yyerror(p, buf);
}
...
...
@@ -2995,7 +2995,7 @@ yywarning_s(parser_state *p, const char *fmt, const char *s)
{
char buf[256];
snprintf(buf,
256
, fmt, s);
snprintf(buf,
sizeof(buf)
, fmt, s);
yywarning(p, buf);
}
...
...
@@ -3702,7 +3702,7 @@ parser_yylex(parser_state *p)
}
if (c2) {
char buf[256];
snprintf(buf,
256
, "invalid character syntax; use ?\\%c", c2);
snprintf(buf,
sizeof(buf)
, "invalid character syntax; use ?\\%c", c2);
yyerror(p, buf);
}
}
...
...
src/time.c
View file @
7c64a2be
...
...
@@ -435,7 +435,7 @@ mrb_time_asctime(mrb_state *mrb, mrb_value self)
tm
=
mrb_get_datatype
(
mrb
,
self
,
&
mrb_time_type
);
if
(
!
tm
)
return
mrb_nil_value
();
d
=
&
tm
->
datetime
;
len
=
snprintf
(
buf
,
256
,
"%s %s %02d %02d:%02d:%02d %s%d"
,
len
=
snprintf
(
buf
,
sizeof
(
buf
)
,
"%s %s %02d %02d:%02d:%02d %s%d"
,
wday_names
[
d
->
tm_wday
],
mon_names
[
d
->
tm_mon
],
d
->
tm_mday
,
d
->
tm_hour
,
d
->
tm_min
,
d
->
tm_sec
,
tm
->
timezone
==
MRB_TIMEZONE_UTC
?
"UTC "
:
""
,
...
...
src/vm.c
View file @
7c64a2be
...
...
@@ -295,7 +295,7 @@ localjump_error(mrb_state *mrb, const char *kind)
int
len
;
mrb_value
exc
;
len
=
snprintf
(
buf
,
256
,
"unexpected %s"
,
kind
);
len
=
snprintf
(
buf
,
sizeof
(
buf
)
,
"unexpected %s"
,
kind
);
exc
=
mrb_exc_new
(
mrb
,
E_LOCALJUMP_ERROR
,
buf
,
len
);
mrb
->
exc
=
(
struct
RObject
*
)
mrb_object
(
exc
);
}
...
...
@@ -308,12 +308,12 @@ argnum_error(mrb_state *mrb, int num)
mrb_value
exc
;
if
(
mrb
->
ci
->
mid
)
{
len
=
snprintf
(
buf
,
256
,
"'%s': wrong number of arguments (%d for %d)"
,
len
=
snprintf
(
buf
,
sizeof
(
buf
)
,
"'%s': wrong number of arguments (%d for %d)"
,
mrb_sym2name
(
mrb
,
mrb
->
ci
->
mid
),
mrb
->
ci
->
argc
,
num
);
}
else
{
len
=
snprintf
(
buf
,
256
,
"wrong number of arguments (%d for %d)"
,
len
=
snprintf
(
buf
,
sizeof
(
buf
)
,
"wrong number of arguments (%d for %d)"
,
mrb
->
ci
->
argc
,
num
);
}
exc
=
mrb_exc_new
(
mrb
,
E_ARGUMENT_ERROR
,
buf
,
len
);
...
...
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