[Issue 10517] New: readln(Char)(Char[] buf) accepts non-mutable buffers
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sun Jun 30 23:35:43 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10517
Summary: readln(Char)(Char[] buf) accepts non-mutable buffers
Product: D
Version: D1
Platform: All
OS/Version: All
Status: ASSIGNED
Keywords: accepts-invalid
Severity: normal
Priority: P2
Component: Phobos
AssignedTo: monarchdodra at gmail.com
ReportedBy: monarchdodra at gmail.com
--- Comment #0 from monarchdodra at gmail.com 2013-06-30 23:35:42 PDT ---
As said in title, and explained in this thread:
http://forum.dlang.org/thread/odkkhkgnahhpklvumghv@forum.dlang.org
--------------------------------
The global readln has a signature that looks like this:
size_t readln(ref char[] buf, dchar terminator = '\n')
File.readln's is:
size_t readln(C)(ref C[] buf, dchar terminator = '\n')
if (isSomeChar!C && !is(C == enum))
You might think "Oh: Global readline isn't templated, it should".
Yes it should, but that's minor and trivial to fix.
The problem is that "C[]" can mean things like "const(char)[]",
which means, basically, "string". This means that the following
code is legal:
string reuseableBuffer; (!)
myFile.readln(reuseableBuffer); //Okey Dokey.
Note: This works perfectly fine, there is no illegal mutation or
anything. It's just that a brand new value is always assigned to
the (not so reuseable) reuseableBuffer slice.
The code handles this, but:
a) It Accepts code this makes little sense, and is most probably
an error that silently passes.
b) While the *code* accepts this, *reading it*, it feels more
like luck then explicitly handled.
c) This can be replaced just as well by:
c.1) "s = myFile.readln();"
c.2) "(s = myFile.readln()).size;" if you want the return value
--------------------------------
Solution(s):
1) File.readln signature must be fixed to accept only mutable buffers.
2) .readln should be templatize to accept [wd]string.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list