diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/DCF.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/DCF.java index c1ea3296306fd9d4b2da85fa1e2298f883134822..5058b639b7eb6e126621226928f797ec8fae0f31 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/DCF.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/DCF.java @@ -78,7 +78,9 @@ public class DCF { continue; } int ix = line.indexOf(':'); - assert (ix > 0); + if (ix <= 0) { + throw RError.error(RError.SHOW_CALLER, RError.Message.LINE_MALFORMED, line); + } fieldName = line.substring(0, ix); // There may be no content on this line, all on a continuation line if (ix < line.length() - 1) { diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java index e6073d8872ca8625902a9dc523dcdeda330d33fd..926ca2cbd3eba1f1a154bde851fe7ac067289d14 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/RError.java @@ -983,7 +983,8 @@ public final class RError extends RuntimeException implements TruffleException { NA_REPLACED("NA replaced by maximum positive value"), NA_INF_REPLACED("-Inf replaced by maximally negative value"), MINUS_INF_REPLACED("NA/Inf replaced by maximum positive value"), - INVALID_FUNCTION_VALUE("invalid function value in '%s'"); + INVALID_FUNCTION_VALUE("invalid function value in '%s'"), + LINE_MALFORMED("Line starting '%s ...' is malformed!"); public final String message; final boolean hasArgs; diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test index 7c7844eec54af3ed8f929db16c05ba7670fdbe5a..2eca1bc5d6875f897e3f953e47433f22975f2139 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test @@ -52919,6 +52919,10 @@ structure(integer(0), .Dim = c(3L, 0L), .Dimnames = list(NULL, #argv <- structure(list(x = structure(c(0.483017750550061 + (0+0i), 0.399143285583705 + (0+0i), 0.0162145779468119 + (0+0i), 0.125083255348727 + (0+0i), 0.0706489166477695 + (0+0i), 0.504917626501992 + (0+0i), 0.327679358422756 + (0+0i), 0.411779605317861 + (0+0i), 0.202413034392521 + (0+0i), 0.307096319855191 + (0+0i), 0.642031987197697 + (0+0i), 0.276873307069764 + (0+0i), 0.103556007146835 + (0+0i), 0.256002754438668 + (0+0i), 0.179779380792752 + (0+0i), 0.247455857461318 + (0+0i), 0.215011228807271 + (0+0i), 0.493673762306571 + (0+0i), 0.653446026844904 + (0+0i), 0.573559894575737 + (0+0i), 0.863887825980783 + (0+0i), 0.637789903208613 + (0+0i), 0.0137805955018848 + (0+0i), 0.529164811130613 + (0+0i), 0.271472703316249 + (0+0i)), .Dim = c(5L, 5L))), .Names = 'x');do.call('rcond', argv) [1] 5.327333e-18 +##com.oracle.truffle.r.test.builtins.TestBuiltin_read.testReadDCF# +#{ f <- tempfile(); write('hi', file=f); read.dcf(f); unlink(f); } +Error in read.dcf(f) : Line starting 'hi ...' is malformed! + ##com.oracle.truffle.r.test.builtins.TestBuiltin_readChar.testreadChar1#Ignored.ImplementationError# #argv <- structure(list(con = as.raw(c(65, 66, 67, 68, 69, 70, 71, 72, 73, 74)), nchars = c(3, 3, 0, 3, 3, 3)), .Names = c('con', 'nchars'));do.call('readChar', argv) [1] "ABC" "DEF" "" "GHI" "J" diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_read.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_read.java new file mode 100644 index 0000000000000000000000000000000000000000..da8aabfc3c48852574314d27bfdd02b6e697c7ba --- /dev/null +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_read.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 3 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 3 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.truffle.r.test.builtins; + +import org.junit.Test; + +import com.oracle.truffle.r.test.TestBase; + +// Checkstyle: stop line length check + +/** + * Tests of read* builtins for example read.dcf. + */ +public class TestBuiltin_read extends TestBase { + + @Test + public void testReadDCF() { + assertEval("{ f <- tempfile(); write('hi', file=f); read.dcf(f); unlink(f); }"); + } + +}