[Issue 6175] String corruption when passing static char arrays to std.conv

2012-05-31 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6175


Kenji Hara  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution||FIXED


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


[Issue 6175] String corruption when passing static char arrays to std.conv

2012-05-22 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6175



--- Comment #8 from github-bugzi...@puremagic.com 2012-05-22 12:40:14 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/phobos

https://github.com/D-Programming-Language/phobos/commit/8d455147cfa35bd514796dfc008ee67142213777
fix Issue 6175 - String corruption when passing static char arrays to std.conv

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


[Issue 6175] String corruption when passing static char arrays to std.conv

2012-05-12 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6175


Kenji Hara  changed:

   What|Removed |Added

   Keywords||pull, wrong-code


--- Comment #7 from Kenji Hara  2012-05-12 09:20:56 PDT ---
https://github.com/D-Programming-Language/phobos/pull/575

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


[Issue 6175] String corruption when passing static char arrays to std.conv

2012-04-19 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6175



--- Comment #6 from Steven Schveighoffer  2012-04-19 
08:01:06 PDT ---
Interesting problem!

So here is what happens.  The IFTI type determined for the statCArr argument is
char[9u], which means it's actually passed as a static array *by value*.

The first toImpl template matches and it looks like this:

/**
If the source type is implicitly convertible to the target type, $(D
to) simply performs the implicit conversion.
 */
T toImpl(T, S)(S value)
if (isImplicitlyConvertible!(S, T))
{
alias isUnsigned isUnsignedInt;

// Conversion from integer to integer, and changing its sign
static if (isUnsignedInt!S && isSignedInt!T && S.sizeof == T.sizeof)
{   // unsigned to signed & same size
enforce(value <= cast(S)T.max,
new ConvOverflowException("Conversion positive overflow"));
}
else static if (isSignedInt!S && isUnsignedInt!T)
{   // signed to unsigned
enforce(0 <= value,
new ConvOverflowException("Conversion negative overflow"));
}

return value;
}

Both of those static ifs fail, so it essentially boils down to this:

char[] toImpl(char[9u] value)
{
   return value;
}

this means it is returning stack data!  I'm surprised this is allowed to
compile, I though the compiler would disallow such obvious escaping of stack
data.

I suppose the "correct" fix is to return value.dup in this case, but I hate the
idea that the entire array is passed on the stack, seems wasteful.

Someone with better template-fu skills than me should tackle this...

BTW, what do we think the "correct" implementation *should* be?  .dup the array
or return a slice of the original?  I don't know if slicing is possible given
IFTI limitations.

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


[Issue 6175] String corruption when passing static char arrays to std.conv

2012-04-19 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6175


Steven Schveighoffer  changed:

   What|Removed |Added

 CC||schvei...@yahoo.com


--- Comment #5 from Steven Schveighoffer  2012-04-19 
07:44:51 PDT ---
(In reply to comment #4)
> import std.conv, std.stdio;
> 
> void main()
> {
> immutable char[9] statCArr = "BlaBlaBla";
> writeln("poupoupidouwah");
> auto res1 = to!(char[])(statCArr);
> writeln(res1);
> writeln(statCArr[]);
> }

This is converting const, so to is likely doing a dup/idup.  If you change res1
to immutable(char)[], it fails in the same way.

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


[Issue 6175] String corruption when passing static char arrays to std.conv

2012-04-19 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6175


SomeDude  changed:

   What|Removed |Added

 CC||lovelyd...@mailmetrash.com


--- Comment #4 from SomeDude  2012-04-19 07:29:05 
PDT ---
Isn't it the normal behaviour ?
If statCArr is declared const or immutable, it works as intended.

import std.conv, std.stdio;

void main()
{
immutable char[9] statCArr = "BlaBlaBla";
writeln("poupoupidouwah");
auto res1 = to!(char[])(statCArr);
writeln(res1);
writeln(statCArr[]);
}


PS E:\DigitalMars\dmd2\samples> rdmd bug.d
poupoupidouwah
BlaBlaBla
BlaBlaBla
PS E:\DigitalMars\dmd2\samples>

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


[Issue 6175] String corruption when passing static char arrays to std.conv

2012-04-05 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6175



--- Comment #3 from Andrej Mitrovic  2012-04-05 
19:46:30 PDT ---
(In reply to comment #2)
> This has now changed to a template error:
> 
> import std.conv;
> 
> void main()
> {
> char[9] statCArr = "blablabla";
> auto res1 = to!(char[])(statCArr);
> }

And now in 2.058 it has reverted back to buggy behavior again:

import std.conv;
import std.stdio;

void main()
{
char[9] statCArr = "blablabla";
auto res1 = to!(char[])(statCArr);
writeln(res1);
}

$ rdmd test.d
$ B @

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


[Issue 6175] String corruption when passing static char arrays to std.conv

2012-01-04 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6175



--- Comment #2 from Andrej Mitrovic  2012-01-04 
07:17:05 PST ---
This has now changed to a template error:

import std.conv;

void main()
{
char[9] statCArr = "blablabla";
auto res1 = to!(char[])(statCArr);
}

D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\conv.d(237): Error: template
std.conv.toImpl(T,S) if (isImplicitlyConvertible!(S,T)) toImpl(T,S) if
(isImplicitlyConvertible!(S,T)) matches more than one template declaration,
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\conv.d(245):toImpl(T,S) if
(isImplicitlyConvertible!(S,T)) and
D:\DMD\dmd2\windows\bin\..\..\src\phobos\std\conv.d(350):toImpl(T,S) if
(isStaticArray!(S))

A simple workaround is to pass a slice:
auto res1 = to!(char[])(statCArr[]);

But since to() seems to have specializations for static arrays I'll leave this
open.

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


[Issue 6175] String corruption when passing static char arrays to std.conv

2011-06-18 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=6175



--- Comment #1 from Andrej Mitrovic  2011-06-18 
10:29:12 PDT ---
I've noticed this while trying to add some additional capability to
std.conv.to. In particular, I've added returning static arrays, and accepting
wchar* and not just char* and converting that to some string/char[] type. Maybe
I could have a go at fixing this too..

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