www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - toStringz with 16 char strings - test.d

reply Evil Mr Henry <Evil_member pathlink.com> writes:
Linux, current compiler as of June 30. The following code:

import std.string;
void main() {
char* num = "x";
char[] testName = std.string.toString(num);
printf("%s\n", std.string.toStringz("1234567890123" ~ testName));
printf("%s\n", std.string.toStringz("12345678901234" ~ testName));
printf("%s\n", std.string.toStringz("123456789012345" ~ testName));
printf("%s\n", std.string.toStringz("1234567890123456" ~ testName));
printf("%s\n", std.string.toStringz("12345678901234567" ~ testName));
}

will output:
1234567890123x
12345678901234x
123456789012345xÿ
1234567890123456x
12345678901234567x

Notice the accented y? It shouldn't be there. This only occurs if the total
string is 16 characters long, and includes a char[].


begin 0644 test.d
M:6UP;W)T('-T9"YS=')I;F<[" IV;VED(&UA:6XH*2!["F-H87(J(&YU;2`]
M(")X(CL*8VAA<EM=('1E<W1.86UE(#T <W1D+G-T<FEN9RYT;U-T<FEN9RAN
M=6TI.PIP<FEN=&8H(B5S7&XB+"!S=&0N<W1R:6YG+G1O4W1R:6YG>B B,3(S


M*3L*<')I;G1F*"(E<UQN(BP <W1D+G-T<FEN9RYT;U-T<FEN9WHH(C$R,S0U
M-C<X.3`Q,C,T-2( ?B!T97-T3F%M92DI.PIP<FEN=&8H(B5S7&XB+"!S=&0N

M92DI.PIP<FEN=&8H(B5S7&XB+"!S=&0N<W1R:6YG+G1O4W1R:6YG>B B,3(S

`
end
Jun 30 2004
next sibling parent "Dan Williams" <dnews ithium.NOSPAM.net> writes:
I cannot reproduce this bug.

Using: DMD 0.9.4, RHEL 3.0, 2.4.21 kernel, GCC 3.2.3, can't think of
anything else important

Also tried on my WinXP system out of interest but no bug there either ;)

My output on both systems is simply:

1234567890123x
12345678901234x
123456789012345x
1234567890123456x
12345678901234567x

What Linux distro and version are you running, with what kernel, and what
version of GCC?


"Evil Mr Henry" <Evil_member pathlink.com> wrote in message
news:cc02p2$2hsb$1 digitaldaemon.com...
 Linux, current compiler as of June 30. The following code:

 import std.string;
 void main() {
 char* num = "x";
 char[] testName = std.string.toString(num);
 printf("%s\n", std.string.toStringz("1234567890123" ~ testName));
 printf("%s\n", std.string.toStringz("12345678901234" ~ testName));
 printf("%s\n", std.string.toStringz("123456789012345" ~ testName));
 printf("%s\n", std.string.toStringz("1234567890123456" ~ testName));
 printf("%s\n", std.string.toStringz("12345678901234567" ~ testName));
 }

 will output:
 1234567890123x
 12345678901234x
 123456789012345xÿ
 1234567890123456x
 12345678901234567x

 Notice the accented y? It shouldn't be there. This only occurs if the
total
 string is 16 characters long, and includes a char[].
Jul 01 2004
prev sibling next sibling parent reply Arcane Jill <Arcane_member pathlink.com> writes:
In article <cc02p2$2hsb$1 digitaldaemon.com>, Evil Mr Henry says...

Notice the accented y? It shouldn't be there. This only occurs if the total
string is 16 characters long, and includes a char[].
How to fix this bug: Explicitly initialize all chars. Workaround: Go back to DMD 0.92 Arcane Jill
Jul 01 2004
parent "Walter" <newshound digitalmars.com> writes:
"Arcane Jill" <Arcane_member pathlink.com> wrote in message
news:cc0tm9$rej$1 digitaldaemon.com...
 In article <cc02p2$2hsb$1 digitaldaemon.com>, Evil Mr Henry says...

Notice the accented y? It shouldn't be there. This only occurs if the
total
string is 16 characters long, and includes a char[].
How to fix this bug: Explicitly initialize all chars. Workaround: Go back to DMD 0.92
Except that 0.94 fixed the bug. <g>
Jul 02 2004
prev sibling parent Ben Hinkle <bhinkle4 juno.com> writes:
are you sure you updated your libphobos.a to 0.94? It's easy to forget if
you have to copy it to somewhere like /usr/lib

Evil Mr Henry wrote:

 Linux, current compiler as of June 30. The following code:
 
 import std.string;
 void main() {
 char* num = "x";
 char[] testName = std.string.toString(num);
 printf("%s\n", std.string.toStringz("1234567890123" ~ testName));
 printf("%s\n", std.string.toStringz("12345678901234" ~ testName));
 printf("%s\n", std.string.toStringz("123456789012345" ~ testName));
 printf("%s\n", std.string.toStringz("1234567890123456" ~ testName));
 printf("%s\n", std.string.toStringz("12345678901234567" ~ testName));
 }
 
 will output:
 1234567890123x
 12345678901234x
 123456789012345x
 1234567890123456x
 12345678901234567x
 
 Notice the accented y? It shouldn't be there. This only occurs if the
 total string is 16 characters long, and includes a char[].
Jul 01 2004