www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10517] New: readln(Char)(Char[] buf) accepts non-mutable buffers

reply d-bugmail puremagic.com writes:
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 gmail.com
        ReportedBy: monarchdodra gmail.com


--- Comment #0 from monarchdodra 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: -------
Jun 30 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10517



--- Comment #1 from monarchdodra gmail.com 2013-07-01 10:23:22 PDT ---
https://github.com/D-Programming-Language/phobos/pull/1381

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 01 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10517



--- Comment #2 from github-bugzilla puremagic.com 2013-07-02 20:55:54 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/97cec336a14c5d433970b930906bfeb68fdccaf3
Fix Issue 10517 - readln(Char)(Char[] buf) accepts non-mutable buffers

Also templatizes a global readln

https://github.com/D-Programming-Language/phobos/commit/3be7a03168c8763a4fef9d62210899d8a9be518c
Merge pull request #1381 from monarchdodra/readln

 Fix Issue 10517 - readln(Char)(Char[] buf) accepts non-mutable buffers

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 02 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10517


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 02 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10517


Martin Krejcirik <mk krej.cz> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |joanbrugueram gmail.com


--- Comment #3 from Martin Krejcirik <mk krej.cz> 2013-10-30 23:44:43 CET ---
*** Issue 11374 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 30 2013