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
12d31c33
Unverified
Commit
12d31c33
authored
Aug 19, 2020
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
"backport" CRuby r46656; #2500
Based on cremno/mruby@d446192
parent
5a7cbebc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
10 deletions
+24
-10
mrbgems/mruby-sprintf/src/sprintf.c
mrbgems/mruby-sprintf/src/sprintf.c
+24
-10
No files found.
mrbgems/mruby-sprintf/src/sprintf.c
View file @
12d31c33
...
...
@@ -196,16 +196,10 @@ check_name_arg(mrb_state *mrb, int posarg, const char *name, size_t len)
check_name_arg(mrb, posarg, name, len),\
(posarg = -2, mrb_hash_fetch(mrb, get_hash(mrb, &hash, argc, argv), id, mrb_undef_value())))
#define GETNUM(n, val) \
for (; p < end && ISDIGIT(*p); p++) {\
if (n > (MRB_INT_MAX - (*p - '0'))/10) {\
mrb_raise(mrb, E_ARGUMENT_ERROR, #val " too big"); \
} \
n = 10 * n + (*p - '0'); \
} \
if (p >= end) { \
mrb_raise(mrb, E_ARGUMENT_ERROR, "malformed format string - %*[0-9]"); \
}
#define GETNUM(n, val) do { \
if (!(p = get_num(mrb, p, end, &(n)))) \
mrb_raise(mrb, E_ARGUMENT_ERROR, #val " too big"); \
} while(0)
#define GETASTER(num) do { \
mrb_value tmp_v; \
...
...
@@ -222,6 +216,26 @@ check_name_arg(mrb_state *mrb, int posarg, const char *name, size_t len)
num = mrb_int(mrb, tmp_v); \
} while (0)
static
const
char
*
get_num
(
mrb_state
*
mrb
,
const
char
*
p
,
const
char
*
end
,
mrb_int
*
valp
)
{
mrb_int
next_n
=
*
valp
;
for
(;
p
<
end
&&
ISDIGIT
(
*
p
);
p
++
)
{
if
(
mrb_int_mul_overflow
(
10
,
next_n
,
&
next_n
))
{
return
NULL
;
}
if
(
INT_MAX
-
(
*
p
-
'0'
)
<
next_n
)
{
return
NULL
;
}
next_n
+=
*
p
-
'0'
;
}
if
(
p
>=
end
)
{
mrb_raise
(
mrb
,
E_ARGUMENT_ERROR
,
"malformed format string - %%*[0-9]"
);
}
*
valp
=
next_n
;
return
p
;
}
static
mrb_value
get_hash
(
mrb_state
*
mrb
,
mrb_value
*
hash
,
mrb_int
argc
,
const
mrb_value
*
argv
)
{
...
...
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