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
5f74721e
Commit
5f74721e
authored
Jul 06, 2013
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1348 from carsonmcdonald/shiftwarningfix
Fix signed/unsigned warning in numeric shift
parents
bccf1259
9a5e78ae
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
2 deletions
+21
-2
src/numeric.c
src/numeric.c
+2
-2
test/t/integer.rb
test/t/integer.rb
+19
-0
No files found.
src/numeric.c
View file @
5f74721e
...
...
@@ -998,7 +998,7 @@ fix_xor(mrb_state *mrb, mrb_value x)
#define NUMERIC_SHIFT_WIDTH_MAX (sizeof(mrb_int)*CHAR_BIT-1)
static
mrb_value
lshift
(
mrb_state
*
mrb
,
mrb_int
val
,
in
t
width
)
lshift
(
mrb_state
*
mrb
,
mrb_int
val
,
size_
t
width
)
{
if
(
width
>
NUMERIC_SHIFT_WIDTH_MAX
)
{
mrb_raisef
(
mrb
,
E_RANGE_ERROR
,
"width(%S) > (%S:sizeof(mrb_int)*CHAR_BIT-1)"
,
...
...
@@ -1010,7 +1010,7 @@ lshift(mrb_state *mrb, mrb_int val, int width)
}
static
mrb_value
rshift
(
mrb_int
val
,
in
t
width
)
rshift
(
mrb_int
val
,
size_
t
width
)
{
if
(
width
>=
NUMERIC_SHIFT_WIDTH_MAX
)
{
if
(
val
<
0
)
{
...
...
test/t/integer.rb
View file @
5f74721e
...
...
@@ -104,6 +104,14 @@ assert('Integer#<<', '15.2.8.3.12') do
# 00010111 (23)
# = 00101110 (46)
assert_equal
23
<<
1
,
46
# Left Shift by a negative is Right Shift
assert_equal
46
<<
-
1
,
23
# Raise when shift is too large
assert_raise
(
RangeError
)
do
2
<<
128
end
end
assert
(
'Integer#>>'
,
'15.2.8.3.13'
)
do
...
...
@@ -111,6 +119,17 @@ assert('Integer#>>', '15.2.8.3.13') do
# 00101110 (46)
# = 00010111 (23)
assert_equal
46
>>
1
,
23
# Right Shift by a negative is Left Shift
assert_equal
23
>>
-
1
,
46
# Don't raise on large Right Shift
assert_equal
23
>>
128
,
0
# Raise when shift is too large
assert_raise
(
RangeError
)
do
2
>>
-
128
end
end
assert
(
'Integer#ceil'
,
'15.2.8.3.14'
)
do
...
...
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