Skip to content
Snippets Groups Projects
Commit ab8c9c88 authored by stepan's avatar stepan
Browse files

Fix: as.raw with string that overflows

parent 7b789b17
No related branches found
No related tags found
No related merge requests found
......@@ -143,6 +143,7 @@ public abstract class CastRawNode extends CastBaseNode {
if (intRawValue != intValue) {
warningBranch.enter();
RError.warning(this, RError.Message.OUT_OF_RANGE);
return RRaw.valueOf((byte) 0);
}
return RRaw.valueOf((byte) intRawValue);
}
......@@ -223,7 +224,7 @@ public abstract class CastRawNode extends CastBaseNode {
if (intValue != intRawValue) {
warningBranch.enter();
outOfRangeWarning = true;
intRawValue = 0;
intValue = 0;
}
}
bdata[i] = (byte) intValue;
......
......@@ -6970,6 +6970,12 @@ Warning messages:
1: NAs introduced by coercion
2: out-of-range values treated as 0 in coercion to raw
 
##com.oracle.truffle.r.test.builtins.TestBuiltin_asraw.testAsRaw#Output.IgnoreWarningContext#
#{ as.raw('10000001') }
[1] 00
Warning message:
out-of-range values treated as 0 in coercion to raw
##com.oracle.truffle.r.test.builtins.TestBuiltin_asraw.testAsRaw#Output.IgnoreWarningContext#
#{ as.raw(-1) }
[1] 00
......@@ -7010,6 +7016,12 @@ out-of-range values treated as 0 in coercion to raw
#{ as.raw(NULL) }
raw(0)
 
##com.oracle.truffle.r.test.builtins.TestBuiltin_asraw.testAsRaw#Output.IgnoreWarningContext#
#{ as.raw(c('10000001', '42')) }
[1] 00 2a
Warning message:
out-of-range values treated as 0 in coercion to raw
##com.oracle.truffle.r.test.builtins.TestBuiltin_asraw.testAsRaw#Output.IgnoreWarningContext#
#{ as.raw(c(1+3i, -2-1i, NA)) }
[1] 01 00 00
......@@ -4,7 +4,7 @@
* http://www.gnu.org/licenses/gpl-2.0.html
*
* Copyright (c) 2012-2014, Purdue University
* Copyright (c) 2013, 2016, Oracle and/or its affiliates
* Copyright (c) 2013, 2017, Oracle and/or its affiliates
*
* All rights reserved.
*/
......@@ -68,5 +68,7 @@ public class TestBuiltin_asraw extends TestBase {
assertEval(Output.IgnoreWarningContext, "{ as.raw(c(1,1000,NA)) }");
assertEval(Output.IgnoreWarningContext, "{ as.raw(c(1L, -2L, 3L)) }");
assertEval(Output.IgnoreWarningContext, "{ as.raw(c(1L, -2L, NA)) }");
assertEval(Output.IgnoreWarningContext, "{ as.raw('10000001') }");
assertEval(Output.IgnoreWarningContext, "{ as.raw(c('10000001', '42')) }");
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment