This is forwarded from http://bugs.debian.org/625918
The attached program computes basename of a 3-bytes long (which denotes 2 characters in some encodings) filename. Everything works fine if a single byte character set is used:
$ LC_ALL=pl_PL.utf8 ./test.exe
basename("\312\253\172") = "\312\253\172"
However, in the Chinese locale the last byte is truncated:
$ LC_ALL=zh_CN.utf8 ./test.exe
basename("\312\253\172") = "\312\253"
The original reporter believes the culprit is the following fragment of mingwex/basename.c:
if( (len = wcstombs( path, refcopy, len )) != (size_t)(-1) )
path[ len ] = '\0';
where len was previously initialized to the number of _characters_ of the input string.
Looking at implementation of dirname(), it might be affected by a similar bug as well.