Back to success stories

Sample of Defect

Project Name CID Checker Category Developer Description
gammu/gammu 50635 DEADCODE Control flow issues The condition was silently wrong - it should have been if (*pos == 0) break;, but if (pos == 0) break; was used instead.
File: /home/travis/build/gammu/gammu/libgammu/misc/coding/coding.c
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
        int tmplen;

        /* Allocate buffer */
        tmp = (char *)calloc(2 * len, sizeof(char));
        if (tmp == NULL) {
                /* We have no memory for XML decoding */
                DecodeUTF8(dest, src, len);
                return;
        }
        if (src == NULL) {
                *dest = 0;
                free(tmp);
                return;
        }

        /* Find ampersand and decode the */
        lastpos = src;
        while ((*lastpos != 0) && ((pos = strchr(lastpos, '&')) != NULL)) {
                /* Store current string */
                strncat(tmp, lastpos, pos - lastpos);
                lastpos = pos;
                /* Skip ampersand */
                pos++;
                /* Detect end of string */
 << At condition "pos == NULL", the value of "pos" cannot be "NULL".
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
                if (pos == 0) break;
                /* Find entity length */
                pos_end = strchr(pos, ';');
                if (pos_end - pos > 6 || pos_end == NULL) {
                        if (pos_end == NULL) {
                                dbgprintf(NULL, "No entity end found, ignoring!\n");
                        } else {
                                dbgprintf(NULL, "Too long html entity, ignoring!\n");
                        }
                        strncat(tmp, lastpos, 1);
                        lastpos++;
                        continue;
                }
                /* Create entity */
                /* strndup would be better, but not portable */
                entity = strdup(pos);
                entity[pos_end - pos] = 0;
                dbgprintf(NULL, "Found XML entity: %s\n", entity);
                if (entity == NULL) break;
                if (entity[0] == '#') {
                        if (entity[1] == 'x' || entity[1] == 'X') {
                                c = strtoull(entity + 2, NULL, 16);
                        } else {
                                c = strtoull(entity + 1, NULL, 10);
                        }
                        dbgprintf(NULL, "Unicode char 0x%04lx\n", c);
                        tmplen = strlen(tmp);
Events:
dead_error_condition coding.c:1718
notnull coding.c:1718
dead_error_line coding.c:1718