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
c12f6427
Commit
c12f6427
authored
May 13, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix overflow error like #2244 on MRB_WORD_BOXING
parent
190d9ebb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
11 deletions
+22
-11
include/mruby/value.h
include/mruby/value.h
+17
-4
src/numeric.c
src/numeric.c
+5
-1
test/driver.c
test/driver.c
+0
-6
No files found.
include/mruby/value.h
View file @
c12f6427
...
...
@@ -27,8 +27,13 @@
# else
typedef
int64_t
mrb_int
;
# define MRB_INT_BIT 64
# define MRB_INT_MIN INT64_MIN
# define MRB_INT_MAX INT64_MAX
# ifdef MRB_WORD_BOXING
# define MRB_INT_MIN (INT64_MIN>>MRB_FIXNUM_SHIFT)
# define MRB_INT_MAX (INT64_MAX>>MRB_FIXNUM_SHIFT)
# else
# define MRB_INT_MIN INT64_MIN
# define MRB_INT_MAX INT64_MAX
# endif
# define PRIdMRB_INT PRId64
# define PRIiMRB_INT PRIi64
# define PRIoMRB_INT PRIo64
...
...
@@ -36,6 +41,9 @@
# define PRIXMRB_INT PRIX64
# endif
#elif defined(MRB_INT16)
# ifdef MRB_WORD_BOXING
# error "MRB_INT16 is too small for MRB_WORD_BOXING."
# endif
typedef
int16_t
mrb_int
;
# define MRB_INT_BIT 16
# define MRB_INT_MIN INT16_MIN
...
...
@@ -43,8 +51,13 @@
#else
typedef
int32_t
mrb_int
;
# define MRB_INT_BIT 32
# define MRB_INT_MIN INT32_MIN
# define MRB_INT_MAX INT32_MAX
# ifdef MRB_WORD_BOXING
# define MRB_INT_MIN (INT32_MIN>>MRB_FIXNUM_SHIFT)
# define MRB_INT_MAX (INT32_MAX>>MRB_FIXNUM_SHIFT)
# else
# define MRB_INT_MIN INT32_MIN
# define MRB_INT_MAX INT32_MAX
# endif
# define PRIdMRB_INT PRId32
# define PRIiMRB_INT PRIi32
# define PRIoMRB_INT PRIo32
...
...
src/numeric.c
View file @
c12f6427
...
...
@@ -687,7 +687,11 @@ int_to_i(mrb_state *mrb, mrb_value num)
return
num
;
}
#ifdef MRB_FIXNUM_SHIFT
#define SQRT_INT_MAX ((mrb_int)1<<((MRB_INT_BIT-1-MRB_FIXNUM_SHIFT)/2))
#else
#define SQRT_INT_MAX ((mrb_int)1<<((MRB_INT_BIT-1)/2))
#endif
/*tests if N*N would overflow*/
#define FIT_SQRT_INT(n) (((n)<SQRT_INT_MAX)&&((n)>=-SQRT_INT_MAX))
...
...
@@ -705,7 +709,7 @@ mrb_fixnum_mul(mrb_state *mrb, mrb_value x, mrb_value y)
if
(
FIT_SQRT_INT
(
a
)
&&
FIT_SQRT_INT
(
b
))
return
mrb_fixnum_value
(
a
*
b
);
c
=
a
*
b
;
if
(
a
!=
0
&&
c
/
a
!=
b
)
{
if
(
(
a
!=
0
&&
c
/
a
!=
b
)
||
!
FIXABLE
(
c
)
)
{
return
mrb_float_value
(
mrb
,
(
mrb_float
)
a
*
(
mrb_float
)
b
);
}
return
mrb_fixnum_value
(
c
);
...
...
test/driver.c
View file @
c12f6427
...
...
@@ -109,15 +109,9 @@ main(int argc, char **argv)
mrbtest
=
mrb_define_module
(
mrb
,
"Mrbtest"
);
#ifdef MRB_WORD_BOXING
mrb_define_const
(
mrb
,
mrbtest
,
"FIXNUM_MAX"
,
mrb_fixnum_value
(
MRB_INT_MAX
>>
MRB_FIXNUM_SHIFT
));
mrb_define_const
(
mrb
,
mrbtest
,
"FIXNUM_MIN"
,
mrb_fixnum_value
(
MRB_INT_MIN
>>
MRB_FIXNUM_SHIFT
));
mrb_define_const
(
mrb
,
mrbtest
,
"FIXNUM_BIT"
,
mrb_fixnum_value
(
MRB_INT_BIT
>>
MRB_FIXNUM_SHIFT
));
#else
mrb_define_const
(
mrb
,
mrbtest
,
"FIXNUM_MAX"
,
mrb_fixnum_value
(
MRB_INT_MAX
));
mrb_define_const
(
mrb
,
mrbtest
,
"FIXNUM_MIN"
,
mrb_fixnum_value
(
MRB_INT_MIN
));
mrb_define_const
(
mrb
,
mrbtest
,
"FIXNUM_BIT"
,
mrb_fixnum_value
(
MRB_INT_BIT
));
#endif
mrb_init_mrbtest
(
mrb
);
ret
=
eval_test
(
mrb
);
...
...
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