The most bizarre bug I have ever seen, Random Chinese translation? How can this happen?



  • I was working with the datalogging of my Qt application when I suddenly did one thing which caused that entire log to change from plain english into Chinese or something. And all that is caused by one single line of code.

    At first I was having this output:

    << 80
    << 3b
    0x80 command case 3b
    << 1
    << 0
    WiD = W1.csv
    size of transfer = 13 bytes"1";"10111213141516171819"
    highNibble = 1 lowNibble = 0
    highNibble = 1 lowNibble = 1
    highNibble = 1 lowNibble = 2
    highNibble = 1 lowNibble = 3
    highNibble = 1 lowNibble = 4
    highNibble = 1 lowNibble = 5
    highNibble = 1 lowNibble = 6
    highNibble = 1 lowNibble = 7
    highNibble = 1 lowNibble = 8
    highNibble = 1 lowNibble = 9
    Text read and send!
    

    Though it is well it lacks something, you don't see the byte value the machine transmits. So in my send function I added one line of code.

    communication_log << cAsHex << ">> \n";  // communication log is a Qdatastream which stuffs bytes in a .txt file
    

    I have near identical line in qDebug(), the debug output did look fine:

    "\u0016"  >>
    highNibble = 1 lowNibble = 6
    "\u0017"  >>
    highNibble = 1 lowNibble = 7
    "\u0018"  >>
    highNibble = 1 lowNibble = 8
    "\u0019"  >>
    highNibble = 1 lowNibble = 9
    Text read and send!
    

    But how did the logfile look like?:

    ਣ㰼㠠ਰ㰼㌠੢砰〸挠浯慭摮挠獡⁥戳㰊‼쌱㺿‾Ἂ㸾ਠ㸊‾
    㸾ਠ㸐‾ᄊ㸾ਠ㸒‾ጊ㸾ਠ㸔‾ᔊ㸾ਠ㸖‾ᜊ㸾ਠ㸘‾ᤊ㸾ਠ㰊‼ਰ楗⁄‽ㅗ挮癳猊穩⁥景琠慲獮敦⁲‽㌱戠瑹獥ㄢ㬢ㄢ㄰ㄱㄲㄳㄴㄵㄶㄷㄸ∹栊杩乨扩汢⁥‽‱潬乷扩汢⁥‽ਰ楨桧楎扢敬㴠ㄠ氠睯楎扢敬㴠ㄠ栊杩乨扩汢⁥‽‱潬乷扩汢⁥‽ਲ楨桧楎扢敬㴠ㄠ氠睯楎扢敬㴠㌠栊杩乨扩汢⁥‽‱潬乷扩汢⁥‽਴楨桧楎扢敬㴠ㄠ氠睯楎扢敬㴠㔠栊杩乨扩汢⁥‽‱潬乷扩汢⁥‽ਸ਼楨桧楎扢敬㴠ㄠ氠睯楎扢敬㴠㜠栊杩乨扩汢⁥‽‱潬乷扩汢⁥‽ਸ楨桧楎扢敬㴠ㄠ氠睯楎扢敬㴠㤠吊硥⁴敲摡愠摮猠湥Ⅴ迂㸾ਠ迂㸾ਠ迂㸾ਠ迂㸾ਠ迂㸾ਠ迂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ诂㸾ਠ诂㸾ਠ軂㸾ਠ軂㸾ਠ賂㸾ਠ賂㸾ਠ跂㸾ਠ跂㸾ਠ诂㸾ਠ诂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ跂㸾ਠ
    

    Everything was in I believe Chinese. For the fun I also stuffed in Google translate. It could not auto ID the language so I manually selected Chinese. It also did not want to translate into english but it did translate in my native language dutch. I must add that this.... thing.. occured while viewing it in the program 'gedit' of ubuntu. Using the terminal and nano it looked normal.

    As example this characters 跂 does not translate in english but in Dutch I got "voet met zes tenen" or "Feet with six toes" :D. Gotta luv computers and programming

    The 'guilty' function is:

    void MainWindow::send(QString c)  // c is a single byte casted to a QString
    {
        timer->start(2);         // sets a timer at 2 ms
    
        serial->write(c.toLatin1()); // sends a byte overthe serial port
        QString cAsHex = QString("%1").arg(c, 0, 16); // makes a hex value to be shown on the CLI
    
        qDebug() << cAsHex << " >>"; // show the send byte as a Hex value
    
        QFile log("communication_log.txt");
        log.open(QIODevice::Append);
        QTextStream communication_log(&log);
        communication_log << cAsHex << ">> \n"; // I tried all kinds of combination and type casts and such, seems to have no effect
        log.close();
    
        while (Timer == true) {;}    // waits for timeOut to happen
    }
    

    How can that one line of code change the text file so gedit things it the content is some kind of unicode for Chinese??



  • Hi, do you delete the ""communication_log.txt" file every time before running your app? Otherwise it could be some junk characters lingering at start of the file that causes your Chinese woes...



  • Maybe using a hex editor viewing the first bytes of the file can help?
    This seems to be a misinterpreted encoding.



  • Hi,
    have you tried:
    log.open(QIODevice::Text | QIODevice::Append);?



  • @hskoglund said in The most bizarre bug I have ever seen, Random Chinese translation? How can this happen?:

    Hi, do you delete the ""communication_log.txt" file every time before running your app? Otherwise it could be some junk characters lingering at start of the file that causes your Chinese woes...

    Yes I do. The log's purpose is to locate bugs so I have no need to keep track of previous logs.

    @artwaw said in The most bizarre bug I have ever seen, Random Chinese translation? How can this happen?:

    Hi,
    have you tried:
    log.open(QIODevice::Text | QIODevice::Append);?

    No I have not. I think I will add it. I already changed some code and it does not happen anymore, but I'll add it anyway ;)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.