Skip to content

Commit

Permalink
Merge pull request #2224 from Hackerpilot/issue-3363
Browse files Browse the repository at this point in the history
Fix issue 3363: std.stream.readf segfaults with immutable format strings
  • Loading branch information
Михаил Страшун committed Jul 11, 2014
2 parents 9e96ee3 + f40df11 commit 911ea31
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion std/stream.d
Expand Up @@ -703,7 +703,8 @@ class Stream : InputStream, OutputStream {
}
if (fmt.length == 0 || i == fmt.length) {
i = 0;
if (arguments[j] is typeid(char[])) {
if (arguments[j] is typeid(string) || arguments[j] is typeid(char[])
|| arguments[j] is typeid(const(char)[])) {
fmt = va_arg!(string)(args);
j++;
continue;
Expand Down Expand Up @@ -1438,6 +1439,23 @@ class Stream : InputStream, OutputStream {
throw new SeekException("Stream is not seekable");
}

unittest { // unit test for Issue 3363
import std.stdio;
immutable fileName ="issue3363.txt";
auto w = File(fileName, "w");
scope (exit) remove(fileName.ptr);
w.write("one two three");
w.close();
auto r = File(fileName, "r");
const(char)[] constChar;
string str;
char[] chars;
r.readf("%s %s %s", &constChar, &str, &chars);
assert (constChar == "one", constChar);
assert (str == "two", str);
assert (chars == "three", chars);
}

unittest { //unit tests for Issue 1668
void tryFloatRoundtrip(float x, string fmt = "", string pad = "") {
auto s = new MemoryStream();
Expand Down

0 comments on commit 911ea31

Please sign in to comment.