roxen.lists.pike.general

Subject Author Date
Re: UTF-8 combine_path() bug Pontus Rodling <pontus[at]digitalfractions[dot]net> 22-10-2009
Martin Stjernholm skrev:
> Pontus Rodling <<pontus[at]digitalfractions.net>> wrote:
>
>   
>> Something crashes hard when using combine_path() with a UTF-8
>> filename.
>>     
>
> Can you please provide a complete test program?
>
>   
This is the code I was working on when i triggered the bug.
Simply put a folder with a UTF-8 name somewhere in c:/test and it should 
cause it to crash.
As an example, c:/test/パイク crashes Pike.

// Pontus
---
int foldercount;

array folders = ({ });

int main() {
folders += ({
Folder("C:/test"),
});

foreach (folders, Folder f) {
write("Indexing: %s\n", f->path);
f->deepindex();
}

write("Folders: %d\n", foldercount);

write("Press enter to quit... ");
Stdio.stdin->read(1);
}

class Folder {
string name;
Folder parent;

string path;

private array subfolders;
private array files;

void create(string n, Folder|void p) {
name = n;
parent = p;

if (parent) path = combine_path(parent->path, name);
else path = name;

foldercount++;
}

void deepindex() {
array a = get_subfolders();
foreach (a, Folder f) {
f->deepindex();
}
}

array get_subfolders() {
if (!subfolders) {
subfolders = ({ });
array a = sort(get_dir(path));
foreach (a, string b) {
// CRASHES HERE
if (Stdio.is_dir(combine_path(path, b))) {
subfolders += ({ Folder(b, this) });
}
}
}

return copy_value(subfolders);
}
}