@@ -17,6 +17,10 @@ alias UnsignedStringBuf = char[20];
1717
1818char [] unsignedToTempString (ulong value, return char [] buf, uint radix = 10 ) @safe
1919{
20+ if (radix < 2 )
21+ // not a valid radix, just return an empty string
22+ return buf[$ .. $];
23+
2024 size_t i = buf.length;
2125 do
2226 {
@@ -74,6 +78,10 @@ unittest
7478 assert (long .sizeof.unsignedToTempString == " 8" );
7579 assert (uint .max.unsignedToTempString == " 4294967295" );
7680 assert (ulong .max.unsignedToTempString == " 18446744073709551615" );
81+
82+ // test bad radices
83+ assert (100. unsignedToTempString(buf, 1 ) == " " );
84+ assert (100. unsignedToTempString(buf, 0 ) == " " );
7785}
7886
7987alias SignedStringBuf = char [20 ];
@@ -151,7 +159,7 @@ unittest
151159 * Returns:
152160 * number of digits
153161 */
154- int numDigits (uint radix = 10 )(ulong value) @safe
162+ int numDigits (uint radix = 10 )(ulong value) @safe if (radix >= 2 && radix <= 36 )
155163{
156164 int n = 1 ;
157165 while (1 )
@@ -197,6 +205,11 @@ unittest
197205 assert (1. numDigits! 2 == 1 );
198206 assert (2. numDigits! 2 == 2 );
199207 assert (3. numDigits! 2 == 2 );
208+
209+ // test bad radices
210+ static assert (! __traits(compiles, 100. numDigits! 1 ()));
211+ static assert (! __traits(compiles, 100. numDigits! 0 ()));
212+ static assert (! __traits(compiles, 100. numDigits! 37 ()));
200213}
201214
202215int dstrcmp ( scope const char [] s1, scope const char [] s2 ) @trusted
0 commit comments