[Issue 1965] New: std.string.toStringz checks too stringent
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Apr 1 05:47:21 PDT 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1965
Summary: std.string.toStringz checks too stringent
Product: DGCC aka GDC
Version: unspecified
Platform: Macintosh
OS/Version: All
Status: NEW
Severity: trivial
Priority: P2
Component: Phobos
AssignedTo: dvdfrdmn at users.sf.net
ReportedBy: fawzi at gmx.ch
If a string containing a zero character is passed to std.string.toStringz then
the checks fail.
Indeed the zero terminated string and the string are different, but I think
that the routine should be seen as working correctly.
(making the tests this actually happens as a string "\0" is passed to
toStringz).
I would replace the check with the one in the patch, but I can understand if
someone argues that the original check is a feature, not a bug.
Fawzi
============
--- string.d (revision 209)
+++ string.d (working copy)
@@ -219,7 +219,9 @@
out (result)
{
if (result)
- { assert(strlen(result) == s.length);
+ {
+ auto clen=strlen(result);
+ assert(clen == s.length || (clen < s.length && s[clen]==0));
assert(memcmp(result, s.ptr, s.length) == 0);
}
}
=================
--
More information about the D.gnu
mailing list