clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name user.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -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 -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -resource-dir /usr/lib/llvm-9/lib/clang/9.0.0 -D openapi_petstore_EXPORTS -I /usr/local/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-9/lib/clang/9.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /home/wing328/Code/openapi-generator/samples/client/petstore/c -ferror-limit 19 -fmessage-length 0 -fvisibility default -fobjc-runtime=gcc -fdiagnostics-show-option -analyzer-output=html -faddrsig -o /tmp/scan-build-2020-12-16-230944-1865-1 -x c /home/wing328/Code/openapi-generator/samples/client/petstore/c/model/user.c
1 | #include <stdlib.h> |
2 | #include <string.h> |
3 | #include <stdio.h> |
4 | #include "user.h" |
5 | |
6 | |
7 | |
8 | user_t *user_create( |
9 | long id, |
10 | char *username, |
11 | char *first_name, |
12 | char *last_name, |
13 | char *email, |
14 | char *password, |
15 | char *phone, |
16 | int user_status |
17 | ) { |
18 | user_t *user_local_var = malloc(sizeof(user_t)); |
19 | if (!user_local_var) { |
20 | return NULL; |
21 | } |
22 | user_local_var->id = id; |
23 | user_local_var->username = username; |
24 | user_local_var->first_name = first_name; |
25 | user_local_var->last_name = last_name; |
26 | user_local_var->email = email; |
27 | user_local_var->password = password; |
28 | user_local_var->phone = phone; |
29 | user_local_var->user_status = user_status; |
30 | |
31 | return user_local_var; |
32 | } |
33 | |
34 | |
35 | void user_free(user_t *user) { |
36 | if(NULL == user){ |
37 | return ; |
38 | } |
39 | listEntry_t *listEntry; |
40 | if (user->username) { |
41 | free(user->username); |
42 | user->username = NULL; |
43 | } |
44 | if (user->first_name) { |
45 | free(user->first_name); |
46 | user->first_name = NULL; |
47 | } |
48 | if (user->last_name) { |
49 | free(user->last_name); |
50 | user->last_name = NULL; |
51 | } |
52 | if (user->email) { |
53 | free(user->email); |
54 | user->email = NULL; |
55 | } |
56 | if (user->password) { |
57 | free(user->password); |
58 | user->password = NULL; |
59 | } |
60 | if (user->phone) { |
61 | free(user->phone); |
62 | user->phone = NULL; |
63 | } |
64 | free(user); |
65 | } |
66 | |
67 | cJSON *user_convertToJSON(user_t *user) { |
68 | cJSON *item = cJSON_CreateObject(); |
69 | |
70 | |
71 | if(user->id) { |
72 | if(cJSON_AddNumberToObject(item, "id", user->id) == NULL) { |
73 | goto fail; |
74 | } |
75 | } |
76 | |
77 | |
78 | |
79 | if(user->username) { |
80 | if(cJSON_AddStringToObject(item, "username", user->username) == NULL) { |
81 | goto fail; |
82 | } |
83 | } |
84 | |
85 | |
86 | |
87 | if(user->first_name) { |
88 | if(cJSON_AddStringToObject(item, "firstName", user->first_name) == NULL) { |
89 | goto fail; |
90 | } |
91 | } |
92 | |
93 | |
94 | |
95 | if(user->last_name) { |
96 | if(cJSON_AddStringToObject(item, "lastName", user->last_name) == NULL) { |
97 | goto fail; |
98 | } |
99 | } |
100 | |
101 | |
102 | |
103 | if(user->email) { |
104 | if(cJSON_AddStringToObject(item, "email", user->email) == NULL) { |
105 | goto fail; |
106 | } |
107 | } |
108 | |
109 | |
110 | |
111 | if(user->password) { |
112 | if(cJSON_AddStringToObject(item, "password", user->password) == NULL) { |
113 | goto fail; |
114 | } |
115 | } |
116 | |
117 | |
118 | |
119 | if(user->phone) { |
120 | if(cJSON_AddStringToObject(item, "phone", user->phone) == NULL) { |
121 | goto fail; |
122 | } |
123 | } |
124 | |
125 | |
126 | |
127 | if(user->user_status) { |
128 | if(cJSON_AddNumberToObject(item, "userStatus", user->user_status) == NULL) { |
129 | goto fail; |
130 | } |
131 | } |
132 | |
133 | return item; |
134 | fail: |
135 | if (item) { |
136 | cJSON_Delete(item); |
137 | } |
138 | return NULL; |
139 | } |
140 | |
141 | user_t *user_parseFromJSON(cJSON *userJSON){ |
142 | |
143 | user_t *user_local_var = NULL; |
144 | |
145 | |
146 | cJSON *id = cJSON_GetObjectItemCaseSensitive(userJSON, "id"); |
147 | if (id) { |
| |
| |
148 | if(!cJSON_IsNumber(id)) |
149 | { |
150 | goto end; |
151 | } |
152 | } |
153 | |
154 | |
155 | cJSON *username = cJSON_GetObjectItemCaseSensitive(userJSON, "username"); |
156 | if (username) { |
| 3 | | Assuming 'username' is null | |
|
| |
157 | if(!cJSON_IsString(username)) |
158 | { |
159 | goto end; |
160 | } |
161 | } |
162 | |
163 | |
164 | cJSON *first_name = cJSON_GetObjectItemCaseSensitive(userJSON, "firstName"); |
165 | if (first_name) { |
| 5 | | Assuming 'first_name' is null | |
|
| |
166 | if(!cJSON_IsString(first_name)) |
167 | { |
168 | goto end; |
169 | } |
170 | } |
171 | |
172 | |
173 | cJSON *last_name = cJSON_GetObjectItemCaseSensitive(userJSON, "lastName"); |
174 | if (last_name) { |
| 7 | | Assuming 'last_name' is null | |
|
| |
175 | if(!cJSON_IsString(last_name)) |
176 | { |
177 | goto end; |
178 | } |
179 | } |
180 | |
181 | |
182 | cJSON *email = cJSON_GetObjectItemCaseSensitive(userJSON, "email"); |
183 | if (email) { |
| 9 | | Assuming 'email' is null | |
|
| |
184 | if(!cJSON_IsString(email)) |
185 | { |
186 | goto end; |
187 | } |
188 | } |
189 | |
190 | |
191 | cJSON *password = cJSON_GetObjectItemCaseSensitive(userJSON, "password"); |
192 | if (password) { |
| 11 | | Assuming 'password' is null | |
|
| |
193 | if(!cJSON_IsString(password)) |
194 | { |
195 | goto end; |
196 | } |
197 | } |
198 | |
199 | |
200 | cJSON *phone = cJSON_GetObjectItemCaseSensitive(userJSON, "phone"); |
201 | if (phone) { |
| 13 | | Assuming 'phone' is non-null | |
|
| |
202 | if(!cJSON_IsString(phone)) |
| 15 | | Assuming the condition is false | |
|
| |
203 | { |
204 | goto end; |
205 | } |
206 | } |
207 | |
208 | |
209 | cJSON *user_status = cJSON_GetObjectItemCaseSensitive(userJSON, "userStatus"); |
210 | if (user_status) { |
| 17 | | Assuming 'user_status' is null | |
|
| |
211 | if(!cJSON_IsNumber(user_status)) |
212 | { |
213 | goto end; |
214 | } |
215 | } |
216 | |
217 | |
218 | user_local_var = user_create ( |
| |
219 | id ? id->valuedouble : 0, |
| |
220 | username ? strdup(username->valuestring) : NULL, |
| |
221 | first_name ? strdup(first_name->valuestring) : NULL, |
| |
222 | last_name ? strdup(last_name->valuestring) : NULL, |
| |
223 | email ? strdup(email->valuestring) : NULL, |
| |
224 | password ? strdup(password->valuestring) : NULL, |
| |
225 | phone ? strdup(phone->valuestring) : NULL, |
| |
| |
226 | user_status ? user_status->valuedouble : 0 |
| |
227 | ); |
228 | |
229 | return user_local_var; |
230 | end: |
231 | return NULL; |
232 | |
233 | } |