www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [bug] listdir W implementation

reply "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
contains the lines:

  clength = std.string.strlen(fileinfo.cFileName);
  wbuf.length = MultiByteToWideChar(0,0,fileinfo.cFileName,clength,null,0);
  n = MultiByteToWideChar(0,0,fileinfo.cFileName,clength,cast(wchar*)wbuf,wbuf.length);
  assert(n == wbuf.length);
  if (!callback(std.utf.toUTF8(wbuf)))
    . . .

It's possible, albiet unlikely, that the filename is changed (to be shorter)
between the two WC2MB calls, and therefore
the assert() is inappropriate.

Should be:

  clength = std.string.strlen(fileinfo.cFileName);
  wbuf.length = MultiByteToWideChar(0,0,fileinfo.cFileName,clength,null,0);
  n = MultiByteToWideChar(0,0,fileinfo.cFileName,clength,cast(wchar*)wbuf,wbuf.length);
  assert(n <= wbuf.length);
  if(n < wbuf.length)
  {
    wbuf = wbuf[0 .. n];
  }
  if (!callback(std.utf.toUTF8(wbuf)))
    . . .
Sep 08 2004
parent "Matthew" <admin stlsoft.dot.dot.dot.dot.org> writes:
Forget everything I just said.

"Matthew" <admin stlsoft.dot.dot.dot.dot.org> wrote in message
news:chorsg$1oi8$1 digitaldaemon.com...
 contains the lines:

   clength = std.string.strlen(fileinfo.cFileName);
   wbuf.length = MultiByteToWideChar(0,0,fileinfo.cFileName,clength,null,0);
   n = MultiByteToWideChar(0,0,fileinfo.cFileName,clength,cast(wchar*)wbuf,wbuf.length);
   assert(n == wbuf.length);
   if (!callback(std.utf.toUTF8(wbuf)))
     . . .

 It's possible, albiet unlikely, that the filename is changed (to be shorter)
between the two WC2MB calls, and
therefore
 the assert() is inappropriate.

 Should be:

   clength = std.string.strlen(fileinfo.cFileName);
   wbuf.length = MultiByteToWideChar(0,0,fileinfo.cFileName,clength,null,0);
   n = MultiByteToWideChar(0,0,fileinfo.cFileName,clength,cast(wchar*)wbuf,wbuf.length);
   assert(n <= wbuf.length);
   if(n < wbuf.length)
   {
     wbuf = wbuf[0 .. n];
   }
   if (!callback(std.utf.toUTF8(wbuf)))
     . . .
Sep 08 2004