OS_ClearXML:
   62|  1.32k|{
   63|  1.32k|    unsigned int i;
   64|   108k|    for (i = 0; i < _lxml->cur; i++) {
  ------------------
  |  Branch (64:17): [True: 106k, False: 1.32k]
  ------------------
   65|   106k|        free(_lxml->el[i]);
   66|   106k|        free(_lxml->ct[i]);
   67|   106k|    }
   68|  1.32k|    _lxml->cur = 0;
   69|  1.32k|    _lxml->fol = 0;
   70|  1.32k|    _lxml->err_line = 0;
   71|       |
   72|  1.32k|    free(_lxml->el);
   73|  1.32k|    _lxml->el = NULL;
   74|       |
   75|  1.32k|    free(_lxml->ct);
   76|  1.32k|    _lxml->ct = NULL;
   77|       |
   78|  1.32k|    free(_lxml->rl);
   79|  1.32k|    _lxml->rl = NULL;
   80|       |
   81|  1.32k|    free(_lxml->tp);
   82|  1.32k|    _lxml->tp = NULL;
   83|       |
   84|  1.32k|    free(_lxml->ck);
   85|  1.32k|    _lxml->ck = NULL;
   86|       |
   87|  1.32k|    free(_lxml->ln);
   88|  1.32k|    _lxml->ln = NULL;
   89|       |
   90|  1.32k|    memset(_lxml->err, '\0', XML_ERR_LENGTH);
  ------------------
  |  |   24|  1.32k|#define XML_ERR_LENGTH  128
  ------------------
   91|  1.32k|}
OS_ReadXML:
   95|  1.32k|{
   96|  1.32k|    int r;
   97|  1.32k|    unsigned int i;
   98|  1.32k|    FILE *fp;
   99|       |
  100|       |    /* Initialize xml structure */
  101|  1.32k|    _lxml->cur = 0;
  102|  1.32k|    _lxml->fol = 0;
  103|  1.32k|    _lxml->el = NULL;
  104|  1.32k|    _lxml->ct = NULL;
  105|  1.32k|    _lxml->tp = NULL;
  106|  1.32k|    _lxml->rl = NULL;
  107|  1.32k|    _lxml->ck = NULL;
  108|  1.32k|    _lxml->ln = NULL;
  109|       |
  110|  1.32k|    _lxml->err_line = 0;
  111|  1.32k|    memset(_lxml->err, '\0', XML_ERR_LENGTH);
  ------------------
  |  |   24|  1.32k|#define XML_ERR_LENGTH  128
  ------------------
  112|       |
  113|  1.32k|    fp = fopen(file, "r");
  114|  1.32k|    if (!fp) {
  ------------------
  |  Branch (114:9): [True: 0, False: 1.32k]
  ------------------
  115|      0|        xml_error(_lxml, "XMLERR: File '%s' not found.", file);
  116|      0|        return (-2);
  117|      0|    }
  118|       |
  119|       |    /* Zero the line */
  120|  1.32k|    _line = 1;
  121|       |
  122|       |    /* Skip a leading <?xml ...?> prolog when present (PR #564 / @lazyp). */
  123|  1.32k|    if (_skip_xml_declaration(fp) < 0) {
  ------------------
  |  Branch (123:9): [True: 47, False: 1.27k]
  ------------------
  124|     47|        xml_error(_lxml, "XMLERR: XML declaration not closed.");
  125|     47|        fclose(fp);
  126|     47|        return (-1);
  127|     47|    }
  128|       |
  129|  1.27k|    if ((r = _ReadElem(fp, 0, _lxml, 0)) < 0) { /* First position */
  ------------------
  |  Branch (129:9): [True: 1.27k, False: 0]
  ------------------
  130|  1.27k|        if (r != LEOF) {
  ------------------
  |  |   18|  1.27k|#define LEOF        -2
  ------------------
  |  Branch (130:13): [True: 1.01k, False: 261]
  ------------------
  131|  1.01k|            fclose(fp);
  132|  1.01k|            return (-1);
  133|  1.01k|        }
  134|  1.27k|    }
  135|       |
  136|  73.9k|    for (i = 0; i < _lxml->cur; i++) {
  ------------------
  |  Branch (136:17): [True: 73.6k, False: 261]
  ------------------
  137|  73.6k|        if (_lxml->ck[i] == 0) {
  ------------------
  |  Branch (137:13): [True: 0, False: 73.6k]
  ------------------
  138|      0|            xml_error(_lxml, "XMLERR: Element '%s' not closed.", _lxml->el[i]);
  139|      0|            fclose(fp);
  140|      0|            return (-1);
  141|      0|        }
  142|  73.6k|    }
  143|       |
  144|    261|    fclose(fp);
  145|    261|    return (0);
  146|    261|}
os_xml.c:xml_error:
   50|  1.06k|{
   51|  1.06k|    va_list args;
   52|  1.06k|    va_start(args, msg);
   53|       |
   54|  1.06k|    memset(_lxml->err, '\0', XML_ERR_LENGTH);
  ------------------
  |  |   24|  1.06k|#define XML_ERR_LENGTH  128
  ------------------
   55|  1.06k|    vsnprintf(_lxml->err, XML_ERR_LENGTH - 1, msg, args);
  ------------------
  |  |   24|  1.06k|#define XML_ERR_LENGTH  128
  ------------------
   56|       |    va_end(args);
   57|  1.06k|    _lxml->err_line = _line;
   58|  1.06k|}
os_xml.c:_skip_xml_declaration:
  152|  1.32k|{
  153|  1.32k|    long start;
  154|  1.32k|    unsigned char sig[5];
  155|  1.32k|    size_t n;
  156|  1.32k|    int c;
  157|  1.32k|    int prev = 0;
  158|  1.32k|    size_t i;
  159|       |
  160|  1.32k|    start = ftell(fp);
  161|  1.32k|    if (start < 0) {
  ------------------
  |  Branch (161:9): [True: 0, False: 1.32k]
  ------------------
  162|      0|        return (0);
  163|      0|    }
  164|       |
  165|       |    /* Optional UTF-8 BOM */
  166|  1.32k|    n = fread(sig, 1, 3, fp);
  167|  1.32k|    if (n == 3 && sig[0] == 0xEF && sig[1] == 0xBB && sig[2] == 0xBF) {
  ------------------
  |  Branch (167:9): [True: 1.25k, False: 70]
  |  Branch (167:19): [True: 33, False: 1.21k]
  |  Branch (167:37): [True: 18, False: 15]
  |  Branch (167:55): [True: 1, False: 17]
  ------------------
  168|      1|        start = ftell(fp);
  169|  1.32k|    } else {
  170|  1.32k|        clearerr(fp);
  171|  1.32k|        if (fseek(fp, start, SEEK_SET) != 0) {
  ------------------
  |  Branch (171:13): [True: 0, False: 1.32k]
  ------------------
  172|      0|            return (0);
  173|      0|        }
  174|  1.32k|    }
  175|       |
  176|  1.32k|    n = fread(sig, 1, 5, fp);
  177|  1.32k|    if (n == 5 &&
  ------------------
  |  Branch (177:9): [True: 1.03k, False: 291]
  ------------------
  178|  1.03k|            sig[0] == (unsigned char)_R_CONFS &&
  ------------------
  |  |   13|  2.35k|#define _R_CONFS    '<'
  ------------------
  |  Branch (178:13): [True: 987, False: 44]
  ------------------
  179|    987|            sig[1] == (unsigned char)_R_HEADER &&
  ------------------
  |  |   16|  2.30k|#define _R_HEADER   '?'
  ------------------
  |  Branch (179:13): [True: 98, False: 889]
  ------------------
  180|     98|            sig[2] == 'x' && sig[3] == 'm' && sig[4] == 'l') {
  ------------------
  |  Branch (180:13): [True: 79, False: 19]
  |  Branch (180:30): [True: 62, False: 17]
  |  Branch (180:47): [True: 48, False: 14]
  ------------------
  181|    288|        for (i = 0; i < n; i++) {
  ------------------
  |  Branch (181:21): [True: 240, False: 48]
  ------------------
  182|    240|            if (sig[i] == '\n') {
  ------------------
  |  Branch (182:17): [True: 0, False: 240]
  ------------------
  183|      0|                _line++;
  184|      0|            }
  185|    240|        }
  186|     48|        prev = 'l';
  187|    525|        while ((c = _xml_fgetc(fp)) != EOF) {
  ------------------
  |  Branch (187:16): [True: 478, False: 47]
  ------------------
  188|    478|            if (prev == _R_HEADER && c == _R_CONFE) {
  ------------------
  |  |   16|    956|#define _R_HEADER   '?'
  ------------------
                          if (prev == _R_HEADER && c == _R_CONFE) {
  ------------------
  |  |   14|     11|#define _R_CONFE    '>'
  ------------------
  |  Branch (188:17): [True: 11, False: 467]
  |  Branch (188:38): [True: 1, False: 10]
  ------------------
  189|      1|                return (0);
  190|      1|            }
  191|    477|            prev = c;
  192|    477|        }
  193|     47|        return (-1);
  194|     48|    }
  195|       |
  196|  1.27k|    clearerr(fp);
  197|  1.27k|    if (fseek(fp, start, SEEK_SET) != 0) {
  ------------------
  |  Branch (197:9): [True: 0, False: 1.27k]
  ------------------
  198|      0|        return (0);
  199|      0|    }
  200|  1.27k|    return (0);
  201|  1.27k|}
os_xml.c:_xml_fgetc:
   38|   615k|{
   39|   615k|    int c;
   40|   615k|    c = fgetc(fp);
   41|       |
   42|   615k|    if (c == '\n') { /* add newline */
  ------------------
  |  Branch (42:9): [True: 3.68k, False: 612k]
  ------------------
   43|  3.68k|        _line++;
   44|  3.68k|    }
   45|       |
   46|   615k|    return (c);
   47|   615k|}
os_xml.c:_ReadElem:
  233|  33.0k|{
  234|  33.0k|    int c;
  235|  33.0k|    unsigned int count = 0;
  236|  33.0k|    unsigned int _currentlycont = 0;
  237|  33.0k|    short int location = -1;
  238|  33.0k|    int retval = -1;
  239|       |
  240|  33.0k|    int prevv = 0;
  241|  33.0k|    char *elem = NULL;
  242|  33.0k|    char *cont = NULL;
  243|  33.0k|    char *closedelim = NULL;
  244|       |
  245|  33.0k|    if (++recursion_level > 1024) {
  ------------------
  |  Branch (245:9): [True: 1, False: 33.0k]
  ------------------
  246|      1|        xml_error(_lxml, "XMLERR: Max recursion level reached.");
  247|      1|        return (-1);
  248|      1|    }
  249|       |
  250|  33.0k|    elem = (char *)calloc(XML_MAXSIZE + 1, sizeof(char));
  ------------------
  |  |   20|  33.0k|#define XML_MAXSIZE          8192
  ------------------
  251|  33.0k|    cont = (char *)calloc(XML_MAXSIZE + 1, sizeof(char));
  ------------------
  |  |   20|  33.0k|#define XML_MAXSIZE          8192
  ------------------
  252|  33.0k|    closedelim = (char *)calloc(XML_MAXSIZE + 1, sizeof(char));
  ------------------
  |  |   20|  33.0k|#define XML_MAXSIZE          8192
  ------------------
  253|       |
  254|  33.0k|    if (!elem || !cont || !closedelim) {
  ------------------
  |  Branch (254:9): [True: 0, False: 33.0k]
  |  Branch (254:18): [True: 0, False: 33.0k]
  |  Branch (254:27): [True: 0, False: 33.0k]
  ------------------
  255|      0|        xml_error(_lxml, "XMLERR: Memory error.");
  256|      0|        goto end;
  257|      0|    }
  258|       |
  259|   317k|    while ((c = _xml_fgetc(fp)) != EOF) {
  ------------------
  |  Branch (259:12): [True: 316k, False: 535]
  ------------------
  260|   316k|        if (c == '\\') {
  ------------------
  |  Branch (260:13): [True: 1.53k, False: 315k]
  ------------------
  261|  1.53k|            prevv = c;
  262|   315k|        } else if (prevv == '\\') {
  ------------------
  |  Branch (262:20): [True: 1.22k, False: 313k]
  ------------------
  263|  1.22k|            if (c != _R_CONFS) {
  ------------------
  |  |   13|  1.22k|#define _R_CONFS    '<'
  ------------------
  |  Branch (263:17): [True: 370, False: 855]
  ------------------
  264|    370|                prevv = 0;
  265|    370|            }
  266|  1.22k|        }
  267|       |
  268|       |        /* Max size */
  269|   316k|        if (count >= XML_MAXSIZE) {
  ------------------
  |  |   20|   316k|#define XML_MAXSIZE          8192
  ------------------
  |  Branch (269:13): [True: 1, False: 316k]
  ------------------
  270|      1|            xml_error(_lxml, "XMLERR: String overflow.");
  271|      1|            goto end;
  272|      1|        }
  273|       |
  274|       |        /* Check for comments */
  275|   316k|        if (c == _R_CONFS) {
  ------------------
  |  |   13|   316k|#define _R_CONFS    '<'
  ------------------
  |  Branch (275:13): [True: 110k, False: 206k]
  ------------------
  276|   110k|            int r = 0;
  277|   110k|            if ((r = _oscomment(fp)) < 0) {
  ------------------
  |  Branch (277:17): [True: 113, False: 110k]
  ------------------
  278|    113|                xml_error(_lxml, "XMLERR: Comment not closed.");
  279|    113|                goto end;
  280|   110k|            } else if (r == 1) {
  ------------------
  |  Branch (280:24): [True: 3.01k, False: 107k]
  ------------------
  281|  3.01k|                continue;
  282|  3.01k|            }
  283|   110k|        }
  284|       |
  285|       |        /* Real checking */
  286|   313k|        if ((location == -1) && (prevv == 0)) {
  ------------------
  |  Branch (286:13): [True: 73.0k, False: 240k]
  |  Branch (286:33): [True: 72.2k, False: 821]
  ------------------
  287|  72.2k|            if (c == _R_CONFS) {
  ------------------
  |  |   13|  72.2k|#define _R_CONFS    '<'
  ------------------
  |  Branch (287:17): [True: 70.6k, False: 1.54k]
  ------------------
  288|  70.6k|                if ((c = fgetc(fp)) == '/') {
  ------------------
  |  Branch (288:21): [True: 1, False: 70.6k]
  ------------------
  289|      1|                    xml_error(_lxml, "XMLERR: Element not opened.");
  290|      1|                    goto end;
  291|  70.6k|                } else {
  292|  70.6k|                    ungetc(c, fp);
  293|  70.6k|                }
  294|  70.6k|                location = 0;
  295|  70.6k|            } else {
  296|  1.54k|                continue;
  297|  1.54k|            }
  298|  72.2k|        }
  299|       |
  300|   241k|        else if ((location == 0) && ((c == _R_CONFE) || isspace(c))) {
  ------------------
  |  |   14|   199k|#define _R_CONFE    '>'
  ------------------
  |  Branch (300:18): [True: 199k, False: 41.7k]
  |  Branch (300:38): [True: 30.0k, False: 169k]
  |  Branch (300:57): [True: 40.4k, False: 129k]
  ------------------
  301|  70.5k|            int _ge = 0;
  302|  70.5k|            int _ga = 0;
  303|  70.5k|            elem[count] = '\0';
  304|       |
  305|       |            /* Remove the / at the end of the element name */
  306|  70.5k|            if (count > 0 && elem[count - 1] == '/') {
  ------------------
  |  Branch (306:17): [True: 2.65k, False: 67.8k]
  |  Branch (306:30): [True: 198, False: 2.45k]
  ------------------
  307|    198|                _ge = '/';
  308|    198|                elem[count - 1] = '\0';
  309|    198|            }
  310|       |
  311|  70.5k|            if (_writememory(elem, XML_ELEM, count + 1, parent, _lxml) < 0) {
  ------------------
  |  Branch (311:17): [True: 0, False: 70.5k]
  ------------------
  312|      0|                goto end;
  313|      0|            }
  314|  70.5k|            _currentlycont = _lxml->cur - 1;
  315|  70.5k|            if (isspace(c)) {
  ------------------
  |  Branch (315:17): [True: 40.4k, False: 30.0k]
  ------------------
  316|  40.4k|                if ((_ga = _getattributes(fp, parent, _lxml)) < 0) {
  ------------------
  |  Branch (316:21): [True: 489, False: 39.9k]
  ------------------
  317|    489|                    goto end;
  318|    489|                }
  319|  40.4k|            }
  320|       |
  321|       |            /* If the element is closed already (finished in />) */
  322|  70.0k|            if ((_ge == '/') || (_ga == '/')) {
  ------------------
  |  Branch (322:17): [True: 198, False: 69.8k]
  |  Branch (322:33): [True: 39.4k, False: 30.3k]
  ------------------
  323|  39.6k|                if (_writecontent("\0", 2, _currentlycont, _lxml) < 0) {
  ------------------
  |  Branch (323:21): [True: 0, False: 39.6k]
  ------------------
  324|      0|                    goto end;
  325|      0|                }
  326|  39.6k|                _lxml->ck[_currentlycont] = 1;
  327|  39.6k|                _currentlycont = 0;
  328|  39.6k|                count = 0;
  329|  39.6k|                location = -1;
  330|       |
  331|  39.6k|                memset(elem, '\0', XML_MAXSIZE);
  ------------------
  |  |   20|  39.6k|#define XML_MAXSIZE          8192
  ------------------
  332|  39.6k|                memset(closedelim, '\0', XML_MAXSIZE);
  ------------------
  |  |   20|  39.6k|#define XML_MAXSIZE          8192
  ------------------
  333|  39.6k|                memset(cont, '\0', XML_MAXSIZE);
  ------------------
  |  |   20|  39.6k|#define XML_MAXSIZE          8192
  ------------------
  334|       |
  335|  39.6k|                if (parent > 0) {
  ------------------
  |  Branch (335:21): [True: 2.32k, False: 37.3k]
  ------------------
  336|  2.32k|                    retval = 0;
  337|  2.32k|                    goto end;
  338|  2.32k|                }
  339|  39.6k|            } else {
  340|  30.3k|                count = 0;
  341|  30.3k|                location = 1;
  342|  30.3k|            }
  343|  70.0k|        }
  344|       |
  345|   170k|        else if ((location == 2) && (c == _R_CONFE)) {
  ------------------
  |  |   14|  4.57k|#define _R_CONFE    '>'
  ------------------
  |  Branch (345:18): [True: 4.57k, False: 166k]
  |  Branch (345:37): [True: 2.12k, False: 2.45k]
  ------------------
  346|  2.12k|            closedelim[count] = '\0';
  347|  2.12k|            if (strcmp(closedelim, elem) != 0) {
  ------------------
  |  Branch (347:17): [True: 135, False: 1.98k]
  ------------------
  348|    135|                xml_error(_lxml, "XMLERR: Element '%s' not closed.", elem);
  349|    135|                goto end;
  350|    135|            }
  351|  1.98k|            if (_writecontent(cont, strlen(cont) + 1, _currentlycont, _lxml) < 0) {
  ------------------
  |  Branch (351:17): [True: 0, False: 1.98k]
  ------------------
  352|      0|                goto end;
  353|      0|            }
  354|  1.98k|            _lxml->ck[_currentlycont] = 1;
  355|  1.98k|            memset(elem, '\0', XML_MAXSIZE);
  ------------------
  |  |   20|  1.98k|#define XML_MAXSIZE          8192
  ------------------
  356|  1.98k|            memset(closedelim, '\0', XML_MAXSIZE);
  ------------------
  |  |   20|  1.98k|#define XML_MAXSIZE          8192
  ------------------
  357|  1.98k|            memset(cont, '\0', XML_MAXSIZE);
  ------------------
  |  |   20|  1.98k|#define XML_MAXSIZE          8192
  ------------------
  358|  1.98k|            _currentlycont = 0;
  359|  1.98k|            count = 0;
  360|  1.98k|            location = -1;
  361|  1.98k|            if (parent > 0) {
  ------------------
  |  Branch (361:17): [True: 1.35k, False: 631]
  ------------------
  362|  1.35k|                retval = 0;
  363|  1.35k|                goto end;
  364|  1.35k|            }
  365|   168k|        } else if ((location == 1) && (c == _R_CONFS) && (prevv == 0)) {
  ------------------
  |  |   13|  36.3k|#define _R_CONFS    '<'
  ------------------
  |  Branch (365:20): [True: 36.3k, False: 132k]
  |  Branch (365:39): [True: 34.1k, False: 2.16k]
  |  Branch (365:58): [True: 33.9k, False: 228]
  ------------------
  366|  33.9k|            if ((c = fgetc(fp)) == '/') {
  ------------------
  |  Branch (366:17): [True: 2.13k, False: 31.7k]
  ------------------
  367|  2.13k|                cont[count] = '\0';
  368|  2.13k|                count = 0;
  369|  2.13k|                location = 2;
  370|  31.7k|            } else {
  371|  31.7k|                ungetc(c, fp);
  372|  31.7k|                ungetc(_R_CONFS, fp);
  ------------------
  |  |   13|  31.7k|#define _R_CONFS    '<'
  ------------------
  373|       |
  374|  31.7k|                if (_ReadElem(fp, parent + 1, _lxml, recursion_level) < 0) {
  ------------------
  |  Branch (374:21): [True: 28.1k, False: 3.68k]
  ------------------
  375|  28.1k|                    goto end;
  376|  28.1k|                }
  377|  3.68k|                count = 0;
  378|  3.68k|            }
  379|   134k|        } else {
  380|   134k|            if (location == 0) {
  ------------------
  |  Branch (380:17): [True: 129k, False: 5.66k]
  ------------------
  381|   129k|                elem[count++] = (char) c;
  382|   129k|            } else if (location == 1) {
  ------------------
  |  Branch (382:24): [True: 2.39k, False: 3.27k]
  ------------------
  383|  2.39k|                cont[count++] = (char) c;
  384|  3.27k|            } else if (location == 2) {
  ------------------
  |  Branch (384:24): [True: 2.45k, False: 821]
  ------------------
  385|  2.45k|                closedelim[count++] = (char) c;
  386|  2.45k|            }
  387|       |
  388|   134k|            if ((_R_CONFS == c) && (prevv != 0)) {
  ------------------
  |  |   13|   134k|#define _R_CONFS    '<'
  ------------------
  |  Branch (388:17): [True: 2.99k, False: 131k]
  |  Branch (388:36): [True: 855, False: 2.13k]
  ------------------
  389|    855|                prevv = 0;
  390|    855|            }
  391|   134k|        }
  392|   313k|    }
  393|    535|    if (location == -1) {
  ------------------
  |  Branch (393:9): [True: 261, False: 274]
  ------------------
  394|    261|        retval = LEOF;
  ------------------
  |  |   18|    261|#define LEOF        -2
  ------------------
  395|    261|        goto end;
  396|    261|    }
  397|       |
  398|    274|    xml_error(_lxml, "XMLERR: End of file and some elements were not closed.");
  399|       |
  400|  33.0k|end:
  401|  33.0k|    free(elem);
  402|  33.0k|    free(cont);
  403|  33.0k|    free(closedelim);
  404|  33.0k|    return (retval);
  405|    274|}
os_xml.c:_oscomment:
  204|   110k|{
  205|   110k|    int c;
  206|   110k|    if ((c = fgetc(fp)) == _R_COM) {
  ------------------
  |  |   15|   110k|#define _R_COM      '!'
  ------------------
  |  Branch (206:9): [True: 3.13k, False: 107k]
  ------------------
  207|  18.9k|        while ((c = _xml_fgetc(fp)) != EOF) {
  ------------------
  |  Branch (207:16): [True: 18.8k, False: 113]
  ------------------
  208|  18.8k|            if (c == _R_COM) {
  ------------------
  |  |   15|  18.8k|#define _R_COM      '!'
  ------------------
  |  Branch (208:17): [True: 1.08k, False: 17.7k]
  ------------------
  209|  1.08k|                if ((c = fgetc(fp)) == _R_CONFE) {
  ------------------
  |  |   14|  1.08k|#define _R_CONFE    '>'
  ------------------
  |  Branch (209:21): [True: 221, False: 860]
  ------------------
  210|    221|                    return (1);
  211|    221|                }
  212|    860|                ungetc(c, fp);
  213|  17.7k|            } else if (c == '-') {  /* W3C way of finishing comments */
  ------------------
  |  Branch (213:24): [True: 4.41k, False: 13.3k]
  ------------------
  214|  4.41k|                if ((c = _xml_fgetc(fp)) == '-') {
  ------------------
  |  Branch (214:21): [True: 3.48k, False: 930]
  ------------------
  215|  3.48k|                    if ((c = fgetc(fp)) == _R_CONFE) {
  ------------------
  |  |   14|  3.48k|#define _R_CONFE    '>'
  ------------------
  |  Branch (215:25): [True: 2.79k, False: 691]
  ------------------
  216|  2.79k|                        return (1);
  217|  2.79k|                    }
  218|    691|                    ungetc(c, fp);
  219|    691|                }
  220|  1.62k|                ungetc(c, fp);
  221|  13.3k|            } else {
  222|  13.3k|                continue;
  223|  13.3k|            }
  224|  18.8k|        }
  225|    113|        return (-1);
  226|   107k|    } else {
  227|   107k|        ungetc(c, fp);
  228|   107k|    }
  229|   107k|    return (0);
  230|   110k|}
os_xml.c:_writememory:
  409|   106k|{
  410|   106k|    char **tmp;
  411|   106k|    int *tmp2;
  412|   106k|    unsigned int *tmp3;
  413|   106k|    XML_TYPE *tmp4;
  414|       |
  415|       |    /* Allocate for the element */
  416|   106k|    tmp = (char **)realloc(_lxml->el, (_lxml->cur + 1) * sizeof(char *));
  417|   106k|    if (tmp == NULL) {
  ------------------
  |  Branch (417:9): [True: 0, False: 106k]
  ------------------
  418|      0|        goto fail;
  419|      0|    }
  420|   106k|    _lxml->el = tmp;
  421|   106k|    _lxml->el[_lxml->cur] = (char *)calloc(size, sizeof(char));
  422|   106k|    if (_lxml->el[_lxml->cur] == NULL) {
  ------------------
  |  Branch (422:9): [True: 0, False: 106k]
  ------------------
  423|      0|        goto fail;
  424|      0|    }
  425|   106k|    strncpy(_lxml->el[_lxml->cur], str, size - 1);
  426|       |
  427|       |    /* Allocate for the content */
  428|   106k|    tmp = (char **)realloc(_lxml->ct, (_lxml->cur + 1) * sizeof(char *));
  429|   106k|    if (tmp == NULL) {
  ------------------
  |  Branch (429:9): [True: 0, False: 106k]
  ------------------
  430|      0|        goto fail;
  431|      0|    }
  432|   106k|    _lxml->ct = tmp;
  433|   106k|    _lxml->ct[_lxml->cur] = NULL;
  434|       |
  435|       |    /* Allocate for the type */
  436|   106k|    tmp4 = (XML_TYPE *) realloc(_lxml->tp, (_lxml->cur + 1) * sizeof(XML_TYPE));
  437|   106k|    if (tmp4 == NULL) {
  ------------------
  |  Branch (437:9): [True: 0, False: 106k]
  ------------------
  438|      0|        goto fail;
  439|      0|    }
  440|   106k|    _lxml->tp = tmp4;
  441|   106k|    _lxml->tp[_lxml->cur] = type;
  442|       |
  443|       |    /* Allocate for the relation */
  444|   106k|    tmp3 = (unsigned int *) realloc(_lxml->rl, (_lxml->cur + 1) * sizeof(unsigned int));
  445|   106k|    if (tmp3 == NULL) {
  ------------------
  |  Branch (445:9): [True: 0, False: 106k]
  ------------------
  446|      0|        goto fail;
  447|      0|    }
  448|   106k|    _lxml->rl = tmp3;
  449|   106k|    _lxml->rl[_lxml->cur] = parent;
  450|       |
  451|       |    /* Allocate for the "check" */
  452|   106k|    tmp2 = (int *) realloc(_lxml->ck, (_lxml->cur + 1) * sizeof(int));
  453|   106k|    if (tmp2 == NULL) {
  ------------------
  |  Branch (453:9): [True: 0, False: 106k]
  ------------------
  454|      0|        goto fail;
  455|      0|    }
  456|   106k|    _lxml->ck = tmp2;
  457|   106k|    _lxml->ck[_lxml->cur] = 0;
  458|       |
  459|       |    /* Allocate for the line */
  460|   106k|    tmp3 = (unsigned int *) realloc(_lxml->ln, (_lxml->cur + 1) * sizeof(unsigned int));
  461|   106k|    if (tmp3 == NULL) {
  ------------------
  |  Branch (461:9): [True: 0, False: 106k]
  ------------------
  462|      0|        goto fail;
  463|      0|    }
  464|   106k|    _lxml->ln = tmp3;
  465|   106k|    _lxml->ln[_lxml->cur] = _line;
  466|       |
  467|       |    /* Attributes does not need to be closed */
  468|   106k|    if (type == XML_ATTR) {
  ------------------
  |  Branch (468:9): [True: 36.3k, False: 70.5k]
  ------------------
  469|  36.3k|        _lxml->ck[_lxml->cur] = 1;
  470|  36.3k|    }
  471|       |
  472|       |    /* Check if it is a variable */
  473|   106k|    if (strcasecmp(XML_VAR, str) == 0) {
  ------------------
  |  |   23|   106k|#define XML_VAR              "var"
  ------------------
  |  Branch (473:9): [True: 263, False: 106k]
  ------------------
  474|    263|        _lxml->tp[_lxml->cur] = XML_VARIABLE_BEGIN;
  475|    263|    }
  476|       |
  477|   106k|    _lxml->cur++;
  478|   106k|    return (0);
  479|       |
  480|      0|fail:
  481|      0|    snprintf(_lxml->err, XML_ERR_LENGTH, "XMLERR: Memory error.");
  ------------------
  |  |   24|      0|#define XML_ERR_LENGTH  128
  ------------------
  482|      0|    return (-1);
  483|   106k|}
os_xml.c:_getattributes:
  499|  40.4k|{
  500|  40.4k|    int location = 0;
  501|  40.4k|    unsigned int count = 0;
  502|  40.4k|    int c;
  503|  40.4k|    int c_to_match = 0;
  504|       |
  505|  40.4k|    char attr[XML_MAXSIZE + 1];
  506|  40.4k|    char value[XML_MAXSIZE + 1];
  507|       |
  508|  40.4k|    memset(attr, '\0', XML_MAXSIZE + 1);
  ------------------
  |  |   20|  40.4k|#define XML_MAXSIZE          8192
  ------------------
  509|  40.4k|    memset(value, '\0', XML_MAXSIZE + 1);
  ------------------
  |  |   20|  40.4k|#define XML_MAXSIZE          8192
  ------------------
  510|       |
  511|   200k|    while ((c = _xml_fgetc(fp)) != EOF) {
  ------------------
  |  Branch (511:12): [True: 200k, False: 205]
  ------------------
  512|   200k|        if (count >= XML_MAXSIZE) {
  ------------------
  |  |   20|   200k|#define XML_MAXSIZE          8192
  ------------------
  |  Branch (512:13): [True: 1, False: 200k]
  ------------------
  513|      1|            attr[count - 1] = '\0';
  514|      1|            xml_error(_lxml,
  515|      1|                      "XMLERR: Overflow attempt at attribute '%.20s'.", attr);
  516|      1|            return (-1);
  517|      1|        }
  518|       |
  519|   200k|        else if ((c == _R_CONFE) || ((location == 0) && (c == '/'))) {
  ------------------
  |  |   14|   200k|#define _R_CONFE    '>'
  ------------------
  |  Branch (519:18): [True: 217, False: 200k]
  |  Branch (519:38): [True: 161k, False: 38.2k]
  |  Branch (519:57): [True: 5.43k, False: 156k]
  ------------------
  520|  5.64k|            if (location == 1) {
  ------------------
  |  Branch (520:17): [True: 1, False: 5.64k]
  ------------------
  521|      1|                xml_error(_lxml, "XMLERR: Attribute '%s' not closed.",
  522|      1|                          attr);
  523|      1|                return (-1);
  524|  5.64k|            } else if ((location == 0) && (count > 0)) {
  ------------------
  |  Branch (524:24): [True: 5.64k, False: 0]
  |  Branch (524:43): [True: 21, False: 5.62k]
  ------------------
  525|     21|                xml_error(_lxml, "XMLERR: Attribute '%s' has no value.",
  526|     21|                          attr);
  527|     21|                return (-1);
  528|  5.62k|            } else if (c == '/') {
  ------------------
  |  Branch (528:24): [True: 5.43k, False: 196]
  ------------------
  529|  5.43k|                return (c);
  530|  5.43k|            } else {
  531|    196|                return (0);
  532|    196|            }
  533|   194k|        } else if ((location == 0) && (c == '=')) {
  ------------------
  |  Branch (533:20): [True: 156k, False: 38.2k]
  |  Branch (533:39): [True: 36.5k, False: 119k]
  ------------------
  534|  36.5k|            attr[count] = '\0';
  535|       |
  536|       |            /* Check for existing attribute with same name */
  537|  36.5k|            unsigned int i = _lxml->cur - 1;
  538|       |            /* Search attributes backwards in same parent */
  539|  45.3k|            while (_lxml->rl[i] == parent && _lxml->tp[i] == XML_ATTR) {
  ------------------
  |  Branch (539:20): [True: 45.3k, False: 0]
  |  Branch (539:46): [True: 8.76k, False: 36.5k]
  ------------------
  540|  8.76k|                if (strcmp(_lxml->el[i], attr) == 0) {
  ------------------
  |  Branch (540:21): [True: 9, False: 8.75k]
  ------------------
  541|      9|                    xml_error(_lxml, "XMLERR: Attribute '%s' already defined.", attr);
  542|      9|                    return (-1);
  543|      9|                }
  544|       |
  545|       |                /* Continue with previous element */
  546|  8.75k|                if (i == 0) {
  ------------------
  |  Branch (546:21): [True: 0, False: 8.75k]
  ------------------
  547|      0|                    break;
  548|      0|                }
  549|  8.75k|                i--;
  550|  8.75k|            }
  551|       |
  552|  36.5k|            c = _xml_fgetc(fp);
  553|  36.5k|            if ((c != '"') && (c != '\'')) {
  ------------------
  |  Branch (553:17): [True: 5.06k, False: 31.5k]
  |  Branch (553:31): [True: 788, False: 4.27k]
  ------------------
  554|    788|                unsigned short int _err = 1;
  555|    788|                if (isspace(c)) {
  ------------------
  |  Branch (555:21): [True: 614, False: 174]
  ------------------
  556|  1.18k|                    while ((c = _xml_fgetc(fp)) != EOF) {
  ------------------
  |  Branch (556:28): [True: 1.15k, False: 26]
  ------------------
  557|  1.15k|                        if (isspace(c)) {
  ------------------
  |  Branch (557:29): [True: 571, False: 588]
  ------------------
  558|    571|                            continue;
  559|    588|                        } else if ((c == '"') || (c == '\'')) {
  ------------------
  |  Branch (559:36): [True: 357, False: 231]
  |  Branch (559:50): [True: 211, False: 20]
  ------------------
  560|    568|                            _err = 0;
  561|    568|                            break;
  562|    568|                        } else {
  563|     20|                            break;
  564|     20|                        }
  565|  1.15k|                    }
  566|    614|                }
  567|    788|                if (_err != 0) {
  ------------------
  |  Branch (567:21): [True: 220, False: 568]
  ------------------
  568|    220|                    xml_error(_lxml,
  569|    220|                              "XMLERR: Attribute '%s' not followed by a \" or \'."
  570|    220|                              , attr);
  571|    220|                    return (-1);
  572|    220|                }
  573|    788|            }
  574|       |
  575|  36.3k|            c_to_match = c;
  576|  36.3k|            location = 1;
  577|  36.3k|            count = 0;
  578|   158k|        } else if ((location == 0) && (isspace(c))) {
  ------------------
  |  Branch (578:20): [True: 119k, False: 38.2k]
  |  Branch (578:39): [True: 437, False: 119k]
  ------------------
  579|    437|            if (count == 0) {
  ------------------
  |  Branch (579:17): [True: 435, False: 2]
  ------------------
  580|    435|                continue;
  581|    435|            } else {
  582|      2|                xml_error(_lxml, "XMLERR: Attribute '%s' has no value.", attr);
  583|      2|                return (-1);
  584|      2|            }
  585|   157k|        } else if ((location == 1) && (c == c_to_match)) {
  ------------------
  |  Branch (585:20): [True: 38.2k, False: 119k]
  |  Branch (585:39): [True: 36.3k, False: 1.96k]
  ------------------
  586|  36.3k|            value[count] = '\0';
  587|       |
  588|  36.3k|            if (_writememory(attr, XML_ATTR, strlen(attr) + 1,
  ------------------
  |  Branch (588:17): [True: 0, False: 36.3k]
  ------------------
  589|  36.3k|                             parent, _lxml) < 0) {
  590|      0|                return (-1);
  591|      0|            }
  592|  36.3k|            if (_writecontent(value, count + 1, _lxml->cur - 1, _lxml) < 0) {
  ------------------
  |  Branch (592:17): [True: 0, False: 36.3k]
  ------------------
  593|      0|                return (-1);
  594|      0|            }
  595|  36.3k|            c = _xml_fgetc(fp);
  596|  36.3k|            if (isspace(c)) {
  ------------------
  |  Branch (596:17): [True: 1.97k, False: 34.3k]
  ------------------
  597|       |                /* Next attribute: start over in this frame instead of
  598|       |                 * recursing (one frame per attribute exhausted the stack)
  599|       |                 */
  600|  1.97k|                location = 0;
  601|  1.97k|                count = 0;
  602|  1.97k|                c_to_match = 0;
  603|  1.97k|                memset(attr, '\0', XML_MAXSIZE + 1);
  ------------------
  |  |   20|  1.97k|#define XML_MAXSIZE          8192
  ------------------
  604|  1.97k|                memset(value, '\0', XML_MAXSIZE + 1);
  ------------------
  |  |   20|  1.97k|#define XML_MAXSIZE          8192
  ------------------
  605|  1.97k|                continue;
  606|  34.3k|            } else if (c == _R_CONFE) {
  ------------------
  |  |   14|  34.3k|#define _R_CONFE    '>'
  ------------------
  |  Branch (606:24): [True: 282, False: 34.0k]
  ------------------
  607|    282|                return (0);
  608|  34.0k|            } else if (c == '/') {
  ------------------
  |  Branch (608:24): [True: 34.0k, False: 30]
  ------------------
  609|  34.0k|                return (c);
  610|  34.0k|            }
  611|       |
  612|     30|            xml_error(_lxml,
  613|     30|                      "XMLERR: Bad attribute closing for '%s'='%s'.",
  614|     30|                      attr, value);
  615|     30|            return (-1);
  616|   121k|        } else if (location == 0) {
  ------------------
  |  Branch (616:20): [True: 119k, False: 1.96k]
  ------------------
  617|   119k|            attr[count++] = (char) c;
  618|   119k|        } else if (location == 1) {
  ------------------
  |  Branch (618:20): [True: 1.96k, False: 0]
  ------------------
  619|  1.96k|            value[count++] = (char) c;
  620|  1.96k|        }
  621|   200k|    }
  622|       |
  623|    205|    xml_error(_lxml, "XMLERR: End of file while reading an attribute.");
  624|    205|    return (-1);
  625|  40.4k|}
os_xml.c:_writecontent:
  486|  77.9k|{
  487|  77.9k|    _lxml->ct[parent] = (char *)calloc(size, sizeof(char));
  488|  77.9k|    if ( _lxml->ct[parent] == NULL) {
  ------------------
  |  Branch (488:10): [True: 0, False: 77.9k]
  ------------------
  489|      0|        snprintf(_lxml->err, XML_ERR_LENGTH, "XMLERR: Memory error.");
  ------------------
  |  |   24|      0|#define XML_ERR_LENGTH  128
  ------------------
  490|      0|        return (-1);
  491|      0|    }
  492|  77.9k|    strncpy(_lxml->ct[parent], str, size - 1);
  493|       |
  494|  77.9k|    return (0);
  495|  77.9k|}

OS_ClearNode:
   20|    519|{
   21|    519|    if (node) {
  ------------------
  |  Branch (21:9): [True: 519, False: 0]
  ------------------
   22|    519|        int i = 0;
   23|  38.9k|        while (node[i]) {
  ------------------
  |  Branch (23:16): [True: 38.3k, False: 519]
  ------------------
   24|  38.3k|            if (node[i]->element) {
  ------------------
  |  Branch (24:17): [True: 38.3k, False: 0]
  ------------------
   25|  38.3k|                free(node[i]->element);
   26|  38.3k|            }
   27|  38.3k|            if (node[i]->content) {
  ------------------
  |  Branch (27:17): [True: 38.3k, False: 0]
  ------------------
   28|  38.3k|                free(node[i]->content);
   29|  38.3k|            }
   30|  38.3k|            if (node[i]->attributes) {
  ------------------
  |  Branch (30:17): [True: 33.5k, False: 4.83k]
  ------------------
   31|  33.5k|                int j = 0;
   32|  67.5k|                while (node[i]->attributes[j]) {
  ------------------
  |  Branch (32:24): [True: 34.0k, False: 33.5k]
  ------------------
   33|  34.0k|                    free(node[i]->attributes[j]);
   34|  34.0k|                    j++;
   35|  34.0k|                }
   36|  33.5k|                free(node[i]->attributes);
   37|  33.5k|            }
   38|  38.3k|            if (node[i]->values) {
  ------------------
  |  Branch (38:17): [True: 33.5k, False: 4.83k]
  ------------------
   39|  33.5k|                int j = 0;
   40|  67.5k|                while (node[i]->values[j]) {
  ------------------
  |  Branch (40:24): [True: 34.0k, False: 33.5k]
  ------------------
   41|  34.0k|                    free(node[i]->values[j]);
   42|  34.0k|                    j++;
   43|  34.0k|                }
   44|  33.5k|                free(node[i]->values);
   45|  33.5k|            }
   46|       |
   47|  38.3k|            node[i]->element = NULL;
   48|  38.3k|            node[i]->content = NULL;
   49|  38.3k|            node[i]->attributes = NULL;
   50|  38.3k|            node[i]->values = NULL;
   51|  38.3k|            free(node[i]);
   52|       |            node[i] = NULL;
   53|  38.3k|            i++;
   54|  38.3k|        }
   55|    519|        free(node);
   56|    519|    }
   57|    519|}
OS_GetElementsbyNode:
   62|  38.1k|{
   63|  38.1k|    unsigned int i, k = 0, m;
   64|  38.1k|    xml_node **ret = NULL;
   65|  38.1k|    xml_node **ret_tmp = NULL;
   66|       |
   67|  38.1k|    if (node == NULL) {
  ------------------
  |  Branch (67:9): [True: 261, False: 37.8k]
  ------------------
   68|    261|        m = 0;
   69|    261|        i = 0;
   70|  37.8k|    } else {
   71|  37.8k|        i = node->key;
   72|  37.8k|        m = _lxml->rl[i++] + 1;
   73|  37.8k|    }
   74|       |
   75|   147k|    for (; i < _lxml->cur; i++) {
  ------------------
  |  Branch (75:12): [True: 147k, False: 375]
  ------------------
   76|   147k|        if (_lxml->tp[i] == XML_ELEM) {
  ------------------
  |  Branch (76:13): [True: 79.1k, False: 68.0k]
  ------------------
   77|  79.1k|            if ((_lxml->rl[i] == m) && (_lxml->el[i] != NULL)) {
  ------------------
  |  Branch (77:17): [True: 38.3k, False: 40.7k]
  |  Branch (77:40): [True: 38.3k, False: 0]
  ------------------
   78|  38.3k|                unsigned int l = i + 1;
   79|       |                /* Allocate for xml_node ** */
   80|  38.3k|                ret_tmp = (xml_node **)realloc(ret, (k + 2) * sizeof(xml_node *));
   81|  38.3k|                if (ret_tmp == NULL) {
  ------------------
  |  Branch (81:21): [True: 0, False: 38.3k]
  ------------------
   82|      0|                    goto fail;
   83|      0|                }
   84|  38.3k|                ret = ret_tmp;
   85|       |
   86|       |                /* Allocate for the xml_node * */
   87|  38.3k|                ret[k] = (xml_node *)calloc(1, sizeof(xml_node));
   88|  38.3k|                ret[k + 1] = NULL;
   89|  38.3k|                if (ret[k] == NULL) {
  ------------------
  |  Branch (89:21): [True: 0, False: 38.3k]
  ------------------
   90|      0|                    goto fail;
   91|      0|                }
   92|       |
   93|  38.3k|                ret[k]->element = NULL;
   94|  38.3k|                ret[k]->content = NULL;
   95|  38.3k|                ret[k]->attributes = NULL;
   96|  38.3k|                ret[k]->values = NULL;
   97|       |
   98|       |                /* Get element */
   99|  38.3k|                ret[k]->element = strdup(_lxml->el[i]);
  100|  38.3k|                if (ret[k]->element == NULL) {
  ------------------
  |  Branch (100:21): [True: 0, False: 38.3k]
  ------------------
  101|      0|                    goto fail;
  102|      0|                }
  103|       |
  104|       |                /* Get content */
  105|  38.3k|                if (_lxml->ct[i]) {
  ------------------
  |  Branch (105:21): [True: 38.3k, False: 0]
  ------------------
  106|  38.3k|                    ret[k]->content = strdup(_lxml->ct[i]);
  107|  38.3k|                    if (ret[k]->content == NULL) {
  ------------------
  |  Branch (107:25): [True: 0, False: 38.3k]
  ------------------
  108|      0|                        goto fail;
  109|      0|                    }
  110|  38.3k|                }
  111|       |                /* Assign key */
  112|  38.3k|                ret[k]->key = i;
  113|       |
  114|       |                /* Get attributes */
  115|  72.4k|                while (l < _lxml->cur) {
  ------------------
  |  Branch (115:24): [True: 72.3k, False: 99]
  ------------------
  116|  72.3k|                    if ((_lxml->tp[l] == XML_ATTR) && (_lxml->rl[l] == m) &&
  ------------------
  |  Branch (116:25): [True: 34.0k, False: 38.2k]
  |  Branch (116:55): [True: 34.0k, False: 0]
  ------------------
  117|  34.0k|                            (_lxml->el[l]) && (_lxml->ct[l])) {
  ------------------
  |  Branch (117:29): [True: 34.0k, False: 0]
  |  Branch (117:47): [True: 34.0k, False: 0]
  ------------------
  118|  34.0k|                        char **tmp;
  119|  34.0k|                        tmp = (char **)realloc(ret[k]->attributes, (l - i + 1) * sizeof(char *));
  120|  34.0k|                        if (tmp == NULL) {
  ------------------
  |  Branch (120:29): [True: 0, False: 34.0k]
  ------------------
  121|      0|                            goto fail;
  122|      0|                        }
  123|  34.0k|                        ret[k]->attributes = tmp;
  124|  34.0k|                        ret[k]->attributes[l - i] = NULL;
  125|  34.0k|                        tmp = (char **)realloc(ret[k]->values, (l - i + 1) * sizeof(char *));
  126|  34.0k|                        if (tmp == NULL) {
  ------------------
  |  Branch (126:29): [True: 0, False: 34.0k]
  ------------------
  127|      0|                            goto fail;
  128|      0|                        }
  129|  34.0k|                        ret[k]->values = tmp;
  130|  34.0k|                        ret[k]->values[l - i] = NULL;
  131|       |
  132|  34.0k|                        ret[k]->attributes[l - i - 1] = strdup(_lxml->el[l]);
  133|  34.0k|                        ret[k]->values[l - i - 1] = strdup(_lxml->ct[l]);
  134|  34.0k|                        if (!(ret[k]->attributes[l - i - 1]) ||
  ------------------
  |  Branch (134:29): [True: 0, False: 34.0k]
  ------------------
  135|  34.0k|                                !(ret[k]->values[l - i - 1])) {
  ------------------
  |  Branch (135:33): [True: 0, False: 34.0k]
  ------------------
  136|      0|                            goto fail;
  137|      0|                        }
  138|  34.0k|                        l++;
  139|  38.2k|                    } else {
  140|  38.2k|                        break;
  141|  38.2k|                    }
  142|  72.3k|                }
  143|  38.3k|                k++;
  144|  38.3k|                continue;
  145|  38.3k|            }
  146|  79.1k|        }
  147|   108k|        if ((_lxml->tp[i] == XML_ELEM) && (m > _lxml->rl[i])) {
  ------------------
  |  Branch (147:13): [True: 40.7k, False: 68.0k]
  |  Branch (147:43): [True: 37.7k, False: 2.97k]
  ------------------
  148|  37.7k|            if (node == NULL) {
  ------------------
  |  Branch (148:17): [True: 0, False: 37.7k]
  ------------------
  149|      0|                continue;
  150|  37.7k|            } else {
  151|  37.7k|                break;
  152|  37.7k|            }
  153|  37.7k|        }
  154|   108k|    }
  155|       |
  156|  38.1k|    return (ret);
  157|       |
  158|      0|fail:
  159|      0|    OS_ClearNode(ret);
  160|       |    return (NULL);
  161|  38.1k|}

LLVMFuzzerTestOneInput:
   21|  1.32k|{
   22|  1.32k|    char path[] = "/tmp/ossec-fuzz-os-xml-XXXXXX";
   23|  1.32k|    int fd;
   24|  1.32k|    FILE *fp;
   25|  1.32k|    OS_XML xml;
   26|  1.32k|    XML_NODE node;
   27|  1.32k|    int i;
   28|       |
   29|  1.32k|    if (data == NULL || size == 0) {
  ------------------
  |  Branch (29:9): [True: 0, False: 1.32k]
  |  Branch (29:25): [True: 0, False: 1.32k]
  ------------------
   30|      0|        return 0;
   31|      0|    }
   32|       |
   33|  1.32k|    fd = mkstemp(path);
   34|  1.32k|    if (fd < 0) {
  ------------------
  |  Branch (34:9): [True: 0, False: 1.32k]
  ------------------
   35|      0|        return 0;
   36|      0|    }
   37|       |
   38|  1.32k|    fp = fdopen(fd, "wb");
   39|  1.32k|    if (!fp) {
  ------------------
  |  Branch (39:9): [True: 0, False: 1.32k]
  ------------------
   40|      0|        close(fd);
   41|      0|        unlink(path);
   42|      0|        return 0;
   43|      0|    }
   44|       |
   45|  1.32k|    if (fwrite(data, 1, size, fp) != size) {
  ------------------
  |  Branch (45:9): [True: 0, False: 1.32k]
  ------------------
   46|      0|        fclose(fp);
   47|      0|        unlink(path);
   48|      0|        return 0;
   49|      0|    }
   50|  1.32k|    fclose(fp);
   51|       |
   52|  1.32k|    memset(&xml, 0, sizeof(xml));
   53|  1.32k|    if (OS_ReadXML(path, &xml) < 0) {
  ------------------
  |  Branch (53:9): [True: 1.06k, False: 261]
  ------------------
   54|  1.06k|        OS_ClearXML(&xml);
   55|  1.06k|        unlink(path);
   56|  1.06k|        return 0;
   57|  1.06k|    }
   58|       |
   59|    261|    node = OS_GetElementsbyNode(&xml, NULL);
   60|    261|    if (node == NULL) {
  ------------------
  |  Branch (60:9): [True: 147, False: 114]
  ------------------
   61|    147|        OS_ClearXML(&xml);
   62|    147|        unlink(path);
   63|    147|        return 0;
   64|    147|    }
   65|       |
   66|    114|    i = 0;
   67|  37.9k|    while (node[i]) {
  ------------------
  |  Branch (67:12): [True: 37.8k, False: 114]
  ------------------
   68|  37.8k|        XML_NODE cnode;
   69|  37.8k|        int j = 0;
   70|       |
   71|  37.8k|        cnode = OS_GetElementsbyNode(&xml, node[i]);
   72|  37.8k|        if (cnode == NULL) {
  ------------------
  |  Branch (72:13): [True: 37.4k, False: 405]
  ------------------
   73|  37.4k|            i++;
   74|  37.4k|            continue;
   75|  37.4k|        }
   76|       |
   77|    937|        while (cnode[j]) {
  ------------------
  |  Branch (77:16): [True: 532, False: 405]
  ------------------
   78|    532|            if (cnode[j]->attributes && cnode[j]->values) {
  ------------------
  |  Branch (78:17): [True: 112, False: 420]
  |  Branch (78:41): [True: 112, False: 0]
  ------------------
   79|    112|                int k = 0;
   80|       |
   81|    320|                while (cnode[j]->attributes[k]) {
  ------------------
  |  Branch (81:24): [True: 208, False: 112]
  ------------------
   82|    208|                    k++;
   83|    208|                }
   84|    112|            }
   85|    532|            j++;
   86|    532|        }
   87|       |
   88|    405|        OS_ClearNode(cnode);
   89|    405|        i++;
   90|    405|    }
   91|       |
   92|    114|    OS_ClearNode(node);
   93|    114|    OS_ClearXML(&xml);
   94|    114|    unlink(path);
   95|    114|    return 0;
   96|    261|}

