...
The managed string library also provides a mechanism for dealing with data sanitization by (optionally) checking that all characters in a string belong to a predefined set of "safe" characters.
The following code shows how the managed string library can be used to create a managed string and retrieve a null-terminated byte string from the managed string.
Code Block |
---|
errno_t retValue;
char *cstr; /* pointer to null-terminated byte string */
string_m str1 = NULL;
retValue = strcreate_m(&str1, "hello, world", 0, NULL);
if (retValue != 0)) {
fprintf(stderr, "Error %d from strcreate_m.\n", retValue);
}
else { /* retrieve null-terminated byte string and print */
retValue = getstr_m(&cstr, str1);
if (retValue != 0) {
fprintf(stderr, "error %d from getstr_m.\n", retValue);
}
printf("(%s)\n", cstr);
free(cstr); /* free null-terminated byte string */
cstr = NULL;
}
|
...
Wiki Markup |
---|
\[[Burch 06|AA. C References#Burch06]\] \[[CERT 06c|AA. C References#CERT 06c]\] \[[ISO/IEC 9899:1999|AA. C References#ISO/IEC 9899-1999]\] Section 7.21, "String handling <string.h><{{string.h}}>" \[[Seacord 05a|AA. C References#Seacord 05a]\] Chapter 2, "Strings" |
...