Bug Summary

File:coaccessible.c
Warning:line 83, column 11
Branch condition evaluates to a garbage value

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name coaccessible.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -fhalf-no-semantic-interposition -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/tmp/build/foma/foma-0.10.0+g279~a2d32b38 -resource-dir /usr/lib/llvm-16/lib/clang/16 -D _GNU_SOURCE -D foma_shared_EXPORTS -I /tmp/build/foma/foma-0.10.0+g279~a2d32b38 -internal-isystem /usr/lib/llvm-16/lib/clang/16/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-missing-field-initializers -Wno-deprecated -Wno-unused-parameter -std=c18 -fdebug-compilation-dir=/tmp/build/foma/foma-0.10.0+g279~a2d32b38 -ferror-limit 19 -fvisibility=hidden -fgnuc-version=4.2.1 -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/build/foma/scan-build/2024-09-11-155945-2678-1 -x c /tmp/build/foma/foma-0.10.0+g279~a2d32b38/coaccessible.c
1/* Foma: a finite-state toolkit and library. */
2/* Copyright © 2008-2021 Mans Hulden */
3
4/* This file is part of foma. */
5
6/* Licensed under the Apache License, Version 2.0 (the "License"); */
7/* you may not use this file except in compliance with the License. */
8/* You may obtain a copy of the License at */
9
10/* http://www.apache.org/licenses/LICENSE-2.0 */
11
12/* Unless required by applicable law or agreed to in writing, software */
13/* distributed under the License is distributed on an "AS IS" BASIS, */
14/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
15/* See the License for the specific language governing permissions and */
16/* limitations under the License. */
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <assert.h>
21#include "foma.h"
22
23struct invtable {
24 int state;
25 struct invtable *next;
26};
27
28struct fsm *fsm_coaccessible(struct fsm *net) {
29
30 struct invtable *inverses, *temp_i, *temp_i_prev, *current_ptr;
31 int i, j, s, t, *coacc, current_state, markcount, *mapping, terminate, new_linecount, new_arccount, *added, old_statecount;
32
33
34 struct fsm_state *fsm;
35
36 fsm = net->states;
37 new_arccount = 0;
38 /* printf("statecount %i\n",net->statecount); */
39 old_statecount = net->statecount;
40 inverses = calloc(net->statecount, sizeof(struct invtable));
41 coacc = malloc(sizeof(int)*(net->statecount));
1
Storing uninitialized value
42 mapping = malloc(sizeof(int)*(net->statecount));
43 added = malloc(sizeof(int)*(net->statecount));
44
45 for (i=0; i < (net->statecount); i++) {
2
Assuming 'i' is >= field 'statecount'
3
Loop condition is false. Execution continues on line 51
46 (inverses+i)->state = -1;
47 *(coacc+i) = 0;
48 *(added+i) = 0;
49 }
50
51 for (i=0; (fsm+i)->state_no != -1; i++) {
4
Assuming the condition is false
5
Loop condition is false. Execution continues on line 69
52 s = (fsm+i)->state_no;
53 t = (fsm+i)->target;
54 if (t != -1 && s != t) {
55
56 if (((inverses+t)->state) == -1) {
57 (inverses+t)->state = s;
58 } else {
59 temp_i = malloc(sizeof(struct invtable));
60 temp_i->next = (inverses+t)->next;
61 (inverses+t)->next = temp_i;
62 temp_i->state = s;
63 }
64 }
65 }
66
67 /* Push & mark finals */
68
69 markcount = 0;
70 for (i=0; (fsm+i)->state_no != -1; i++) {
6
Loop condition is false. Execution continues on line 78
71 if ((fsm+i)->final_state && (!*(coacc+((fsm+i)->state_no)))) {
72 int_stack_push((fsm+i)->state_no);
73 *(coacc+(fsm+i)->state_no) = 1;
74 markcount++;
75 }
76 }
77
78 terminate = 0;
79 while(!int_stack_isempty()) {
7
Assuming the condition is true
8
Loop condition is true. Entering loop body
80 current_state = int_stack_pop();
81 current_ptr = inverses+current_state;
82 while(current_ptr != NULL((void*)0) && current_ptr->state != -1) {
9
Assuming 'current_ptr' is not equal to NULL
10
Loop condition is true. Entering loop body
83 if (!*(coacc+(current_ptr->state))) {
11
Branch condition evaluates to a garbage value
84 *(coacc+(current_ptr->state)) = 1;
85 int_stack_push(current_ptr->state);
86 markcount++;
87 }
88 current_ptr = current_ptr->next;
89 }
90 if (markcount >= net->statecount) {
91 /* printf("Already coacc\n"); */
92 terminate = 1;
93 int_stack_clear();
94 break;
95 }
96 }
97
98
99 if (terminate == 0) {
100 *mapping = 0; /* state 0 always exists */
101 new_linecount = 0;
102 for (i=1,j=0; i < (net->statecount);i++) {
103 if (*(coacc+i) == 1) {
104 j++;
105 *(mapping+i) = j;
106 }
107 }
108
109 for (i=0,j=0; (fsm+i)->state_no != -1; i++) {
110 if (i > 0 && (fsm+i)->state_no != (fsm+i-1)->state_no && (fsm+i-1)->final_state && !*(added+((fsm+i-1)->state_no))) {
111 add_fsm_arc(fsm, j++, *(mapping+((fsm+i-1)->state_no)), -1, -1, -1, 1, (fsm+i-1)->start_state);
112 new_linecount++;
113 *(added+((fsm+i-1)->state_no)) = 1;
114 /* printf("addf ad %i\n",i); */
115 }
116 if (*(coacc+((fsm+i)->state_no)) && (((fsm+i)->target == -1) || *(coacc+((fsm+i)->target)))) {
117 (fsm+j)->state_no = *(mapping+((fsm+i)->state_no));
118 if ((fsm+i)->target == -1) {
119 (fsm+j)->target = -1;
120 } else {
121 (fsm+j)->target = *(mapping+((fsm+i)->target));
122 }
123 (fsm+j)->final_state = (fsm+i)->final_state;
124 (fsm+j)->start_state = (fsm+i)->start_state;
125 (fsm+j)->in = (fsm+i)->in;
126 (fsm+j)->out = (fsm+i)->out;
127 j++;
128 new_linecount++;
129 *(added+(fsm+i)->state_no) = 1;
130 if ((fsm+i)->target != -1) {
131 new_arccount++;
132 }
133 }
134 }
135
136 if ((i > 1) && ((fsm+i-1)->final_state) && *(added+((fsm+i-1)->state_no)) == 0) {
137 /* printf("addf\n"); */
138 add_fsm_arc(fsm, j++, *(mapping+((fsm+i-1)->state_no)), -1, -1, -1, 1, (fsm+i-1)->start_state);
139 new_linecount++;
140 }
141
142 if (new_linecount == 0) {
143 add_fsm_arc(fsm, j++, 0, -1, -1, -1, -1, -1);
144 }
145
146 add_fsm_arc(fsm, j, -1, -1, -1, -1, -1, -1);
147 if (markcount == 0) {
148 /* We're dealing with the empty language */
149 free(fsm);
150 net->states = fsm_empty();
151 fsm_sigma_destroy(net->sigma);
152 net->sigma = sigma_create();
153 }
154 net->linecount = new_linecount;
155 net->arccount = new_arccount;
156 net->statecount = markcount;
157 }
158
159 /* printf("Markccount %i \n",markcount); */
160
161 for (i = 0; i < old_statecount ; i++) {
162 for (temp_i = inverses+i; temp_i != NULL((void*)0) ; ) {
163 temp_i_prev = temp_i;
164 temp_i = temp_i->next;
165 if (temp_i_prev != inverses+i)
166 free(temp_i_prev);
167 }
168 }
169 free(inverses);
170
171 free(coacc);
172 free(added);
173 free(mapping);
174 net->is_pruned = YES1;
175 return(net);
176}