MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlEscapeFormatString

Function xmlEscapeFormatString

ThirdParty/libxml2/vtklibxml2/xmlstring.c:1153–1198  ·  view source on GitHub ↗

* xmlEscapeFormatString: * @msg: a pointer to the string in which to escape '%' characters. * Must be a heap-allocated buffer created by libxml2 that may be * returned, or that may be freed and replaced. * * Replaces the string pointed to by 'msg' with an escaped string. * Returns the same string with all '%' characters escaped. */

Source from the content-addressed store, hash-verified

1151 * Returns the same string with all '%' characters escaped.
1152 */
1153xmlChar *
1154xmlEscapeFormatString(xmlChar **msg)
1155{
1156 xmlChar *msgPtr = NULL;
1157 xmlChar *result = NULL;
1158 xmlChar *resultPtr = NULL;
1159 size_t count = 0;
1160 size_t msgLen = 0;
1161 size_t resultLen = 0;
1162
1163 if (!msg || !*msg)
1164 return(NULL);
1165
1166 for (msgPtr = *msg; *msgPtr != '\0'; ++msgPtr) {
1167 ++msgLen;
1168 if (*msgPtr == '%')
1169 ++count;
1170 }
1171
1172 if (count == 0)
1173 return(*msg);
1174
1175 if ((count > INT_MAX) || (msgLen > INT_MAX - count))
1176 return(NULL);
1177 resultLen = msgLen + count + 1;
1178 result = (xmlChar *) xmlMallocAtomic(resultLen);
1179 if (result == NULL) {
1180 /* Clear *msg to prevent format string vulnerabilities in
1181 out-of-memory situations. */
1182 xmlFree(*msg);
1183 *msg = NULL;
1184 return(NULL);
1185 }
1186
1187 for (msgPtr = *msg, resultPtr = result; *msgPtr != '\0'; ++msgPtr, ++resultPtr) {
1188 *resultPtr = *msgPtr;
1189 if (*msgPtr == '%')
1190 *(++resultPtr) = '%';
1191 }
1192 result[resultLen - 1] = '\0';
1193
1194 xmlFree(*msg);
1195 *msg = result;
1196
1197 return *msg;
1198}
1199

Callers 4

LIBXML_ATTR_FORMATFunction · 0.85
xmlSchemaSimpleTypeErrFunction · 0.85
FREE_AND_NULLFunction · 0.85
xmlRelaxNGGetErrorStringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected