The use of nsprintf

Source: Internet
Author: User

extern long nsprintf (char *str, unsigned long ullen, const char *str, char *fmt, ...);

This function is a private implementation of H3C, and the difference from sprintf is that the function return value is the length of the source string. The maximum assembly length is ullen, and the trailing string does not automatically add "/0"

The non-applicable method of the function:

nsprintf (szUserName, sizeof (szUserName), "ABCDEFG");

It is not allowed to use a constant string as an entry parameter in a function. The reason is that the constant string needs to consume local storage space, you can define the required output string as a global variable, and change the input parameter to the first address of the string.

nsprintf (szUserName, sizeof (szUserName), pstexecdata->szusername);

This usage is also inappropriate, because the string pstexecdata->szusername itself may have%s formatted characters, the consequences of how to be determined.

The correct usage is:

nsprintf (szUserName, sizeof (szUserName), "%s", pstexecdata->szusername);

You can define lint rules to help check

Definition rule : lintheader.h

extern long sprintf (char *str, const char *str, char *fmt, ...);

extern long nsprintf (char *str, unsigned long ullen, const char *str, char *fmt, ...);

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.