Fixed defects

List of Defects

Error: CLANG_WARNING: [#def1]
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/dump_database.c:32: included_from: Included from here.
libchewing-0.6.0-build/libchewing-0.6.0/include/internal/memory-private.h:35:12: warning[core.NullDereference]: Array access (from variable 'uptr') results in a null pointer dereference
#   33|       const unsigned char *uptr = ptr;
#   34|   
#   35|->     val = (uptr[0] << 0) | (uptr[1] << 8);
#   36|       return val;
#   37|   }

Error: CPPCHECK_WARNING: [#def2]
libchewing-0.6.0-build/libchewing-0.6.0/src/bopomofo.c: information[normalCheckLevelMaxBranches]: Limiting analysis of branches. Use --check-level=exhaustive to analyze all branches.

Error: COMPILER_WARNING (CWE-563): [#def3]
libchewing-0.6.0-build/libchewing-0.6.0/src/chewing-sql.c: scope_hint: In function ‘TerminateUserphrase’
libchewing-0.6.0-build/libchewing-0.6.0/src/chewing-sql.c:482:9: warning[-Wunused-but-set-variable]: variable ‘ret’ set but not used
#  482 |     int ret;
#      |         ^~~
#  480|   {
#  481|       size_t i;
#  482|->     int ret;
#  483|   
#  484|       UpdateLifeTime(pgdata);

Error: CLANG_WARNING: [#def4]
libchewing-0.6.0-build/libchewing-0.6.0/src/chewing-sql.c:496:5: warning[deadcode.DeadStores]: Value stored to 'ret' is never read
#  494|       }
#  495|   
#  496|->     ret = sqlite3_close(pgdata->staticData.db);
#  497|       assert(SQLITE_OK == ret);
#  498|       pgdata->staticData.db = NULL;

Error: CPPCHECK_WARNING: [#def5]
libchewing-0.6.0-build/libchewing-0.6.0/src/chewingio.c: information[normalCheckLevelMaxBranches]: Limiting analysis of branches. Use --check-level=exhaustive to analyze all branches.

Error: CPPCHECK_WARNING: [#def6]
libchewing-0.6.0-build/libchewing-0.6.0/src/chewingutil.c: information[normalCheckLevelMaxBranches]: Limiting analysis of branches. Use --check-level=exhaustive to analyze all branches.

Error: GCC_ANALYZER_WARNING: [#def7]
libchewing-0.6.0-build/libchewing-0.6.0/src/chewingutil.c: scope_hint: In function ‘RemoveSelectElement’
libchewing-0.6.0-build/libchewing-0.6.0/src/chewingutil.c:957:5: warning[-Wanalyzer-overlapping-buffers]: overlapping buffers passed as arguments to ‘strcpy’
libchewing-0.6.0-build/libchewing-0.6.0/src/chewingutil.c:21: included_from: Included from here.
/usr/include/string.h:141:14: note: the behavior of ‘strcpy’ is undefined for overlapping buffers
#  955|           return;
#  956|       pgdata->selectInterval[i] = pgdata->selectInterval[pgdata->nSelect];
#  957|->     strcpy(pgdata->selectStr[i], pgdata->selectStr[pgdata->nSelect]);
#  958|   }
#  959|   

Error: GCC_ANALYZER_WARNING (CWE-457): [#def8]
libchewing-0.6.0-build/libchewing-0.6.0/src/chewingutil.c: scope_hint: In function ‘InitSymbolTable’
libchewing-0.6.0-build/libchewing-0.6.0/src/chewingutil.c:1342:5: warning[-Wanalyzer-use-of-uninitialized-value]: use of uninitialized value ‘entry’
libchewing-0.6.0-build/libchewing-0.6.0/src/chewingutil.c:29: included_from: Included from here.
libchewing-0.6.0-build/libchewing-0.6.0/src/chewingutil.c:1283:12: note: in expansion of macro ‘ALC’
libchewing-0.6.0-build/libchewing-0.6.0/src/chewingutil.c:1288:13: note: in expansion of macro ‘ALC’
libchewing-0.6.0-build/libchewing-0.6.0/src/chewingutil.c:1288:13: note: in expansion of macro ‘ALC’
libchewing-0.6.0-build/libchewing-0.6.0/src/chewingutil.c:1288:13: note: in expansion of macro ‘ALC’
# 1340|       if (!pgdata->staticData.symbolTable)
# 1341|           goto error;
# 1342|->     memcpy(pgdata->staticData.symbolTable, entry, size);
# 1343|   
# 1344|       ret = 0;

Error: CLANG_WARNING: [#def9]
libchewing-0.6.0-build/libchewing-0.6.0/src/chewingutil.c:1348:5: warning[core.NonNullParamChecker]: Null pointer passed to 1st parameter expecting 'nonnull'
# 1346|       free(entry);
# 1347|       free(line);
# 1348|->     fclose(file);
# 1349|       free(filename);
# 1350|       return ret;

Error: GCC_ANALYZER_WARNING (CWE-476): [#def10]
libchewing-0.6.0-build/libchewing-0.6.0/src/chewingutil.c:1354:9: warning[-Wanalyzer-null-dereference]: dereference of NULL ‘entry’
libchewing-0.6.0-build/libchewing-0.6.0/src/chewingutil.c:1283:12: note: in expansion of macro ‘ALC’
# 1352|     error:
# 1353|       for (i = 0; i < pgdata->staticData.nSymbolEntry; ++i) {
# 1354|->         free(entry[i]);
# 1355|       }
# 1356|       goto end;

Error: CPPCHECK_WARNING: [#def11]
libchewing-0.6.0-build/libchewing-0.6.0/src/choice.c: information[normalCheckLevelMaxBranches]: Limiting analysis of branches. Use --check-level=exhaustive to analyze all branches.

Error: CPPCHECK_WARNING (CWE-682): [#def12]
libchewing-0.6.0-build/libchewing-0.6.0/src/common/key2pho.c:149: error[nullPointerArithmetic]: Overflow in pointer arithmetic, NULL pointer is subtracted.
#  147|               pTarget = findptr + 1;
#  148|           }
#  149|->         _index = findptr - key_str[kbtype];
#  150|           ueStrNCpy(ueStrSeek(pho, i), ueConstStrSeek(ph_str, _index), 1, STRNCPY_NOT_CLOSE);
#  151|       }

Error: CPPCHECK_WARNING: [#def13]
libchewing-0.6.0-build/libchewing-0.6.0/src/pinyin.c: information[normalCheckLevelMaxBranches]: Limiting analysis of branches. Use --check-level=exhaustive to analyze all branches.

Error: GCC_ANALYZER_WARNING (CWE-688): [#def14]
libchewing-0.6.0-build/libchewing-0.6.0/src/pinyin.c: scope_hint: In function ‘PinyinToBopomofo’
libchewing-0.6.0-build/libchewing-0.6.0/src/pinyin.c:194:9: warning[-Wanalyzer-null-argument]: use of NULL ‘initial’ where non-null expected
<built-in>: note: argument 2 of ‘__builtin_strcpy’ must be non-null
#  192|           strcpy(s, seq);
#  193|           initial = strtok(s, " ");
#  194|->         strcpy(bopomofoKeySeq, initial);
#  195|           initial = strtok(NULL, " ");
#  196|           strcpy(bopomofoKeySeqAlt, initial);

Error: GCC_ANALYZER_WARNING (CWE-688): [#def15]
libchewing-0.6.0-build/libchewing-0.6.0/src/pinyin.c:196:9: warning[-Wanalyzer-null-argument]: use of NULL ‘initial’ where non-null expected
<built-in>: note: argument 2 of ‘__builtin_strcpy’ must be non-null
#  194|           strcpy(bopomofoKeySeq, initial);
#  195|           initial = strtok(NULL, " ");
#  196|->         strcpy(bopomofoKeySeqAlt, initial);
#  197|           return 0;
#  198|       }

Error: CPPCHECK_WARNING: [#def16]
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c: information[normalCheckLevelMaxBranches]: Limiting analysis of branches. Use --check-level=exhaustive to analyze all branches.

Error: GCC_ANALYZER_WARNING (CWE-127): [#def17]
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:30: included_from: Included from here.
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c: scope_hint: In function ‘strip’
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:143:51: warning[-Wanalyzer-out-of-bounds]: stack-based buffer under-read
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:143:51: note: valid subscripts for ‘buf’ are ‘[0]’ to ‘[1023]’
#  └───────────────────────┘
#              ^
#  141|       /* remove tailing space */
#  142|       end = line + strlen(line) - 1;
#  143|->     while (end >= line && isspace((unsigned char) *end)) {
#  144|           *end = 0;
#  145|           --end;

Error: GCC_ANALYZER_WARNING (CWE-124): [#def18]
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:144:14: warning[-Wanalyzer-out-of-bounds]: stack-based buffer underwrite
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:144:14: note: valid subscripts for ‘buf’ are ‘[0]’ to ‘[1023]’
#  142|       end = line + strlen(line) - 1;
#  143|       while (end >= line && isspace((unsigned char) *end)) {
#  144|->         *end = 0;
#  145|           --end;
#  146|       }

Error: CPPCHECK_WARNING (CWE-457): [#def19]
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:311: warning[uninitvar]: Uninitialized variable: &word.index
#  309|           ueStrNCpy(word.text->phrase, ueStrSeek(phrase_data[num_phrase_data].phrase, i), 1, 1);
#  310|           word.text->phone[0] = phrase_data[num_phrase_data].phone[i];
#  311|->         found_word = bsearch(&word, word_data, num_word_data, sizeof(word), compare_word_by_text);
#  312|           if ((found_word == NULL ||
#  313|                (phrase_len == 1 &&

Error: GCC_ANALYZER_WARNING (CWE-775): [#def20]
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c: scope_hint: In function ‘read_phone_cin’
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:395:21: warning[-Wanalyzer-file-leak]: leak of FILE ‘fopen(filename, "r")’
#  393|   
#  394|       strip(buf);
#  395|->     if (strlen(buf) == 0)
#  396|           return;
#  397|   

Error: GCC_ANALYZER_WARNING (CWE-401): [#def21]
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:395:21: warning[-Wanalyzer-malloc-leak]: leak of ‘fopen(filename, "r")’
#  393|   
#  394|       strip(buf);
#  395|->     if (strlen(buf) == 0)
#  396|           return;
#  397|   

Error: GCC_ANALYZER_WARNING (CWE-775): [#def22]
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:441:12: warning[-Wanalyzer-file-leak]: leak of FILE ‘fopen(filename, "r")’
#  439|           ret = fgets(buf, sizeof(buf), phone_cin);
#  440|           ++line_num;
#  441|->         if (!ret) {
#  442|               fprintf(stderr, "%s: No expected %s %s\n", filename, CHARDEF, BEGIN);
#  443|               exit(-1);

Error: GCC_ANALYZER_WARNING (CWE-401): [#def23]
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:441:12: warning[-Wanalyzer-malloc-leak]: leak of ‘fopen(filename, "r")’
#  439|           ret = fgets(buf, sizeof(buf), phone_cin);
#  440|           ++line_num;
#  441|->         if (!ret) {
#  442|               fprintf(stderr, "%s: No expected %s %s\n", filename, CHARDEF, BEGIN);
#  443|               exit(-1);

Error: GCC_ANALYZER_WARNING (CWE-688): [#def24]
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:448:14: warning[-Wanalyzer-null-argument]: use of NULL ‘ret’ where non-null expected
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:34: included_from: Included from here.
/usr/include/string.h:156:12: note: argument 1 of ‘strcmp’ must be non-null
#  446|           strip(buf);
#  447|           ret = strtok(buf, " \t");
#  448|->         if (!strcmp(ret, CHARDEF)) {
#  449|               ret = strtok(NULL, " \t");
#  450|               if (!strcmp(ret, BEGIN))

Error: GCC_ANALYZER_WARNING (CWE-775): [#def25]
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:450:16: warning[-Wanalyzer-file-leak]: leak of FILE ‘fopen(filename, "r")’
#  448|           if (!strcmp(ret, CHARDEF)) {
#  449|               ret = strtok(NULL, " \t");
#  450|->             if (!strcmp(ret, BEGIN))
#  451|                   status = HAS_CHARDEF_BEGIN;
#  452|               else {

Error: GCC_ANALYZER_WARNING (CWE-401): [#def26]
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:450:16: warning[-Wanalyzer-malloc-leak]: leak of ‘fopen(filename, "r")’
#  448|           if (!strcmp(ret, CHARDEF)) {
#  449|               ret = strtok(NULL, " \t");
#  450|->             if (!strcmp(ret, BEGIN))
#  451|                   status = HAS_CHARDEF_BEGIN;
#  452|               else {

Error: GCC_ANALYZER_WARNING (CWE-688): [#def27]
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:450:18: warning[-Wanalyzer-null-argument]: use of NULL ‘ret’ where non-null expected
/usr/include/string.h:156:12: note: argument 1 of ‘strcmp’ must be non-null
#  448|           if (!strcmp(ret, CHARDEF)) {
#  449|               ret = strtok(NULL, " \t");
#  450|->             if (!strcmp(ret, BEGIN))
#  451|                   status = HAS_CHARDEF_BEGIN;
#  452|               else {

Error: GCC_ANALYZER_WARNING (CWE-775): [#def28]
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:462:12: warning[-Wanalyzer-file-leak]: leak of FILE ‘fopen(filename, "r")’
#  460|           ret = fgets(buf, sizeof(buf), phone_cin);
#  461|           ++line_num;
#  462|->         if (!ret) {
#  463|               fprintf(stderr, "%s: No expected %s %s\n", filename, CHARDEF, END);
#  464|               exit(-1);

Error: GCC_ANALYZER_WARNING (CWE-401): [#def29]
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:462:12: warning[-Wanalyzer-malloc-leak]: leak of ‘fopen(filename, "r")’
#  460|           ret = fgets(buf, sizeof(buf), phone_cin);
#  461|           ++line_num;
#  462|->         if (!ret) {
#  463|               fprintf(stderr, "%s: No expected %s %s\n", filename, CHARDEF, END);
#  464|               exit(-1);

Error: GCC_ANALYZER_WARNING (CWE-775): [#def30]
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:471:16: warning[-Wanalyzer-file-leak]: leak of FILE ‘fopen(filename, "r")’
#  469|               strtok(buf, " \t");
#  470|               ret = strtok(NULL, " \t");
#  471|->             if (!strcmp(ret, END))
#  472|                   status = HAS_CHARDEF_END;
#  473|               else {

Error: GCC_ANALYZER_WARNING (CWE-401): [#def31]
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:471:16: warning[-Wanalyzer-malloc-leak]: leak of ‘fopen(filename, "r")’
#  469|               strtok(buf, " \t");
#  470|               ret = strtok(NULL, " \t");
#  471|->             if (!strcmp(ret, END))
#  472|                   status = HAS_CHARDEF_END;
#  473|               else {

Error: GCC_ANALYZER_WARNING (CWE-688): [#def32]
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:471:18: warning[-Wanalyzer-null-argument]: use of NULL ‘ret’ where non-null expected
/usr/include/string.h:156:12: note: argument 1 of ‘strcmp’ must be non-null
#  469|               strtok(buf, " \t");
#  470|               ret = strtok(NULL, " \t");
#  471|->             if (!strcmp(ret, END))
#  472|                   status = HAS_CHARDEF_END;
#  473|               else {

Error: GCC_ANALYZER_WARNING (CWE-476): [#def33]
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c: scope_hint: In function ‘write_index_tree’
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:650:19: warning[-Wanalyzer-possible-null-dereference]: dereference of possibly-NULL ‘queue’
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:44: included_from: Included from here.
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:647:13: note: in expansion of macro ‘ALC’
libchewing-0.6.0-build/libchewing-0.6.0/src/tools/init_database.c:647:13: note: in expansion of macro ‘ALC’
#  648|       assert(queue);
#  649|   
#  650|->     queue[head++] = root;
#  651|       while (head != tail) {
#  652|           p = queue[tail++];

Error: CPPCHECK_WARNING: [#def34]
libchewing-0.6.0-build/libchewing-0.6.0/src/tree.c: information[normalCheckLevelMaxBranches]: Limiting analysis of branches. Use --check-level=exhaustive to analyze all branches.

Error: GCC_ANALYZER_WARNING (CWE-476): [#def35]
libchewing-0.6.0-build/libchewing-0.6.0/src/tree.c: scope_hint: In function ‘CheckUserChoose’
libchewing-0.6.0-build/libchewing-0.6.0/src/tree.c:155:17: warning[-Wanalyzer-possible-null-dereference]: dereference of possibly-NULL ‘p_phr’
libchewing-0.6.0-build/libchewing-0.6.0/src/tree.c: scope_hint: In function ‘CheckUserChoose’
libchewing-0.6.0-build/libchewing-0.6.0/src/tree.c:31: included_from: Included from here.
libchewing-0.6.0-build/libchewing-0.6.0/src/tree.c:129:21: note: in expansion of macro ‘ALC’
#  153|       if (pUserPhraseData == NULL)
#  154|         goto end;
#  155|->     p_phr->freq = -1;
#  156|       do {
#  157|           for (chno = 0; chno < nSelect; chno++) {

Error: GCC_ANALYZER_WARNING (CWE-476): [#def36]
libchewing-0.6.0-build/libchewing-0.6.0/src/tree.c: scope_hint: In function ‘SaveRecord’
libchewing-0.6.0-build/libchewing-0.6.0/src/tree.c:705:15: warning[-Wanalyzer-possible-null-dereference]: dereference of possibly-NULL ‘now’
libchewing-0.6.0-build/libchewing-0.6.0/src/tree.c:702:11: note: in expansion of macro ‘ALC’
libchewing-0.6.0-build/libchewing-0.6.0/src/tree.c:702:11: note: in expansion of macro ‘ALC’
#  703|   
#  704|       assert(now);
#  705|->     now->next = ptd->phList;
#  706|       now->arrIndex = ALC(int, nInter);
#  707|   

Error: GCC_ANALYZER_WARNING (CWE-688): [#def37]
libchewing-0.6.0-build/libchewing-0.6.0/src/tree.c:710:5: warning[-Wanalyzer-possible-null-argument]: use of possibly-NULL ‘calloc((long unsigned int)nInter, 4)’ where non-null expected
libchewing-0.6.0-build/libchewing-0.6.0/src/tree.c:702:11: note: in expansion of macro ‘ALC’
libchewing-0.6.0-build/libchewing-0.6.0/src/tree.c:706:21: note: in expansion of macro ‘ALC’
<built-in>: note: argument 1 of ‘__builtin_memcpy’ must be non-null
#  708|       assert(now->arrIndex);
#  709|       now->nInter = nInter;
#  710|->     memcpy(now->arrIndex, record, nInter * sizeof(int));
#  711|       ptd->phList = now;
#  712|   }

Error: CLANG_WARNING: [#def38]
libchewing-0.6.0-build/libchewing-0.6.0/src/tree.c:829:18: warning[core.NullDereference]: Access to field 'next' results in a dereference of a null pointer (loaded from variable 'former')
#  827|       former = tdt->phList;
#  828|       for (i = 0; i < ppo->nNumCut - 1; i++) {
#  829|->         former = former->next;
#  830|           assert(former);
#  831|       }

Error: CLANG_WARNING: [#def39]
libchewing-0.6.0-build/libchewing-0.6.0/src/tree.c:836:20: warning[core.NullDereference]: Access to field 'next' results in a dereference of a null pointer (loaded from field 'next')
#  834|       want = former->next;
#  835|       assert(want);
#  836|->     former->next = former->next->next;
#  837|   
#  838|       /* prepend to front of list */

Error: CLANG_WARNING: [#def40]
libchewing-0.6.0-build/libchewing-0.6.0/src/tree.c:1005:1: warning[unix.Malloc]: Potential memory leak
# 1003|       for (end = 0; end < pgdata->nPhoneSeq - 1; ++end)
# 1004|           FreeRecord(highest_score[end]);
# 1005|-> }
# 1006|   
# 1007|   int Phrasing(ChewingData *pgdata, int all_phrasing)

Error: CPPCHECK_WARNING: [#def41]
libchewing-0.6.0-build/libchewing-0.6.0/src/userphrase-sql.c: information[normalCheckLevelMaxBranches]: Limiting analysis of branches. Use --check-level=exhaustive to analyze all branches.

Scan Properties

analyzer-version-clang18.1.7
analyzer-version-cppcheck2.14.2
analyzer-version-gcc14.1.1
analyzer-version-gcc-analyzer14.1.1
analyzer-version-shellcheck0.10.0
diffbase-analyzer-version-clang18.1.7
diffbase-analyzer-version-cppcheck2.14.2
diffbase-analyzer-version-gcc14.1.1
diffbase-analyzer-version-gcc-analyzer14.1.1
diffbase-analyzer-version-shellcheck0.10.0
diffbase-enabled-pluginsclang, cppcheck, gcc, shellcheck
diffbase-exit-code0
diffbase-hostip-172-16-1-186.us-west-2.compute.internal
diffbase-mock-configfedora-41-x86_64
diffbase-project-namelibchewing-0.8.4-2.fc41
diffbase-store-results-to/tmp/tmp7hxon3pr/libchewing-0.8.4-2.fc41.tar.xz
diffbase-time-created2024-07-03 14:35:03
diffbase-time-finished2024-07-03 14:37:33
diffbase-toolcsmock
diffbase-tool-args'/usr/bin/csmock' '-r' 'fedora-41-x86_64' '-t' 'cppcheck,gcc,clang,shellcheck' '-o' '/tmp/tmp7hxon3pr/libchewing-0.8.4-2.fc41.tar.xz' '--gcc-analyze' '/tmp/tmp7hxon3pr/libchewing-0.8.4-2.fc41.src.rpm'
diffbase-tool-versioncsmock-3.5.3-1.el9
enabled-pluginsclang, cppcheck, gcc, shellcheck
exit-code0
hostip-172-16-1-186.us-west-2.compute.internal
mock-configfedora-41-x86_64
project-namelibchewing-0.6.0-4.fc40
store-results-to/tmp/tmpgmze51ps/libchewing-0.6.0-4.fc40.tar.xz
time-created2024-07-03 14:33:00
time-finished2024-07-03 14:34:32
titleFixed defects
toolcsmock
tool-args'/usr/bin/csmock' '-r' 'fedora-41-x86_64' '-t' 'cppcheck,gcc,clang,shellcheck' '-o' '/tmp/tmpgmze51ps/libchewing-0.6.0-4.fc40.tar.xz' '--gcc-analyze' '/tmp/tmpgmze51ps/libchewing-0.6.0-4.fc40.src.rpm'
tool-versioncsmock-3.5.3-1.el9