Diagnosis of KPilot/Palm's messy text

kpilotpalm

It is a pain of ass that Palm does not support Unicode, definitely a big design flaw. It is also a pity that CJKOS would not support the Unicode either, we lost the last chance to patch the system by third party hack. I have to use the GBK encoding in Palm before the legendary PalmOS Garnet or Access Linux Platform available. Unfortunately, the KPilot fails to synchronize the name of the contacts from the KAddressbook, for example, 钟章环 becomes 章&, ^. It is quite curious that part of the string is encoded correctly. Later, I dig into the code, and found this code snippet:

if (!text.isEmpty()) {
    fAddressInfo.entry[field] = (char *) malloc(text.length() + 1);
    strlcpy(fAddressInfo.entry[field], codec()->fromUnicode(text), text.length() + 1);
 }

The bug results in that the length of the UTF8 encoded string is not the same as the GBK encoded string. A workaround is like this:

if (!text.isEmpty()) {
    QCString locale = codec()->fromUnicode(text);
    fAddressInfo.entry[field] = (char *) malloc(locale.length() + 1);
    strlcpy(fAddressInfo.entry[field], locale, locale.length() + 1);
}

It has been submitted to the KDE Bugzilla, Bug 138108.