0xcd (205) Problems

Source: Internet
Author: User

I encountered a very strange problem when debugging slanagent yesterday.

Slanserver and slanagent run in debug version, and get various agent data, which has been running well. However, a test is written in Python.Program,
Osinfo is obtained from the slanagent, and errors keep occurring when parsing the osversion and Osmend. Slanagent uses UTF-8 to transmit strings.
After obtaining the string in Python, it also uses UTF-8 for parsing. However, Python reports an error saying that some bytes cannot be decode.

After debugging the slanagent, it is found that when converting to UTF-8 for transmission, if a 100-byte array is uploaded, but the content in the array is less than 100 bytes, the extra class capacity will be filled
0xcd (that is, 205). It is strange that 0xcd is never used. Shouldn't the string Terminator be 0x0? Why does it become 0xcd for no reason? Why is this 0xcd?
Come on.

After checking on the internet, I found that 0xcd was automatically added by the debug version of VC. For a char array that is allocated space but not initialized, VC initializes all the bytes to 0xcd (CD indicates clear data), indicating that they have not been initialized. This can prevent errors in some cases.

The problem is clear, and it is easy to solve. When allocating space with new, use memset to initialize the space immediately after the allocation, so there will be no problem.

BTW: although this 0xcd has an error in Python, it has never encountered a problem in slanserver, and for characters ending with 0x25
String, multibytetowidechar, this function does not parse a series of 0xcd as real characters. This multibytetowidechar is also quite

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.