* xmlStrncatNew: * @str1: first xmlChar string * @str2: second xmlChar string * @len: the len of @str2 or < 0 * * same as xmlStrncat, but creates a new string. The original * two strings are not freed. If @len is < 0 then the length * will be calculated automatically. * * Returns a new xmlChar * or NULL */
| 490 | * Returns a new xmlChar * or NULL |
| 491 | */ |
| 492 | xmlChar * |
| 493 | xmlStrncatNew(const xmlChar *str1, const xmlChar *str2, int len) { |
| 494 | int size; |
| 495 | xmlChar *ret; |
| 496 | |
| 497 | if (len < 0) { |
| 498 | len = xmlStrlen(str2); |
| 499 | if (len < 0) |
| 500 | return(NULL); |
| 501 | } |
| 502 | if (str1 == NULL) |
| 503 | return(xmlStrndup(str2, len)); |
| 504 | if ((str2 == NULL) || (len == 0)) |
| 505 | return(xmlStrdup(str1)); |
| 506 | |
| 507 | size = xmlStrlen(str1); |
| 508 | if ((size < 0) || (size > INT_MAX - len)) |
| 509 | return(NULL); |
| 510 | ret = (xmlChar *) xmlMalloc((size_t) size + len + 1); |
| 511 | if (ret == NULL) |
| 512 | return(NULL); |
| 513 | memcpy(ret, str1, size); |
| 514 | memcpy(&ret[size], str2, len); |
| 515 | ret[size + len] = 0; |
| 516 | return(ret); |
| 517 | } |
| 518 | |
| 519 | /** |
| 520 | * xmlStrcat: |
no test coverage detected