From 2bec7fc296582b32f033b751d49efcbaedfa64b0 Mon Sep 17 00:00:00 2001 From: Tomoya Tanjo Date: Thu, 9 Oct 2014 19:04:18 +0900 Subject: [PATCH] Make std.file.DirEntry._ensureStatDone safe --- std/file.d | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/std/file.d b/std/file.d index 4abec9cdd..ebe548134 100644 --- a/std/file.d +++ b/std/file.d @@ -2274,12 +2274,16 @@ else version(Posix) This is to support lazy evaluation, because doing stat's is expensive and not always needed. +/ - void _ensureStatDone() + void _ensureStatDone() @safe { + static auto trustedStat(in char[] path, stat_t* buf) @trusted + { + return stat(path.tempCString(), buf); + } if(_didStat) return; - enforce(stat(_name.tempCString(), &_statBuf) == 0, + enforce(trustedStat(_name, &_statBuf) == 0, "Failed to stat file `" ~ _name ~ "'"); _didStat = true;