[Issue 11734] New: undefined behavior with dirEntries

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Dec 13 00:16:20 PST 2013


https://d.puremagic.com/issues/show_bug.cgi?id=11734

           Summary: undefined behavior with dirEntries
           Product: D
           Version: D2
          Platform: All
        OS/Version: Linux
            Status: NEW
          Severity: blocker
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: timothee.cour2 at gmail.com


--- Comment #0 from Timothee Cour <timothee.cour2 at gmail.com> 2013-12-13 00:16:17 PST ---
The code below produces segfaults (probably due to GC errors, it varies and can
lead to other undefined behavior) depending on number of directories $nb_dirs.
This is particularly annoying as it leads to very hard to find bugs. I've
reduced to the following.

To reproduce:

temp_dir=/tmp/some_temp_dir/
nb_dirs=50 #may need to try different values to see the segfault; typically
<100
rm -r $temp_dir
dmd -run path/to/main.d $temp_dir $nb_dirs

Note, $nb_dirs seems to depend on $temp_dir, but is typically reproducible on a
given machine for a given $temp_dir.

Note, it works fine on OSX, but fails on several different ubuntu 64 bit
machines (Ubuntu 12.04.1 LTS, Ubuntu 12.04.3 LTS).

----
import std.file;
import std.array;
import std.stdio;

alias DirEntry T;

auto children(T entry){
    if(!entry.isDir)
      return DirEntry[].init;
    auto entries=dirEntries(entry.name,SpanMode.shallow, false);
    auto temp=entries.array;
    return temp;
}

struct BFS{
  T[] q;
  this(T a){
    q~=a;
  }
  void popFront(){
    auto temp=q[0];
    auto temp2=children(q[0]);
    foreach(b;temp2)
      q~=b;
    q=q[1..$];
  }
  auto front(){
    return q[0];
  }
  bool empty(){
    return !q.length;
  }
}

void main(string[]args){
  string dir=args[1];
  import std.conv;
  size_t nb=args[2].to!size_t;
  create_dirs(dir,nb);
  BFS bfs=BFS(T(dir));
  auto temp=bfs.array;
}

void create_dirs(string dir,size_t nb){
  import std.conv;
  import std.file;
  if(!dir.exists)
    mkdir(dir);
  foreach(i;0..nb){
    import std.string;
    string dir2=format("%s%03s",dir,i);
    writeln(dir2);
    if(!dir2.exists)
      mkdir(dir2);
  }
}
----

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list