Thread overview
[Issue 18256] Using std.range.put to put a character into a dchar[] segfaults
Jan 17, 2018
Jack Stouffer
Jan 17, 2018
Jack Stouffer
Mar 22, 2018
John Colvin
Mar 22, 2018
Jack Stouffer
Mar 22, 2018
John Colvin
January 17, 2018
https://issues.dlang.org/show_bug.cgi?id=18256

Jack Stouffer <jack@jackstouffer.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://issues.dlang.org/sh
                   |                            |ow_bug.cgi?id=14998

--
January 17, 2018
https://issues.dlang.org/show_bug.cgi?id=18256

Jack Stouffer <jack@jackstouffer.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|installer                   |phobos

--
March 22, 2018
https://issues.dlang.org/show_bug.cgi?id=18256

John Colvin <john.loughran.colvin@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |john.loughran.colvin@gmail.
                   |                            |com
         Resolution|---                         |INVALID

--- Comment #1 from John Colvin <john.loughran.colvin@gmail.com> ---
You're writing to a string literal, which isn't allowed.

change to

dchar[] a = "aaa"d.dup;

and it works fine.

--
March 22, 2018
https://issues.dlang.org/show_bug.cgi?id=18256

Jack Stouffer <jack@jackstouffer.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |---

--- Comment #2 from Jack Stouffer <jack@jackstouffer.com> ---
(In reply to John Colvin from comment #1)
> You're writing to a string literal, which isn't allowed.
> 
> change to
> 
> dchar[] a = "aaa"d.dup;
> 
> and it works fine.

I'm aware it's not allowed. The operative term was segfault, as opposed to giving an error.

--
March 22, 2018
https://issues.dlang.org/show_bug.cgi?id=18256

John Colvin <john.loughran.colvin@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from John Colvin <john.loughran.colvin@gmail.com> ---
This is nothing to do with `put`. As far as `put` is concerned it's been given a mutable buffer.

A segfault is a good outcome when you try to write to a string literal.

Do you mean a compile-time error? If so:

I suggest opening an enhancement request for something like "Disallow obvious cases of writing to string literals" or similar, but I doubt you'll get much traction with it as it's only practically possible to do in trivial cases and only occurs when someone has already broken the rules by casting away immutable.

If you mean a runtime error:

That's what the segfault is for. There's no need to duplicate the work that the CPU does (with all the performance implications that would have).


I'm gonna close this again, re-open if you're really motivated but I think a new issue would be better, without the confusion of `put`.

--