clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name order.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/order.c
1 | #include <stdlib.h> |
2 | #include <string.h> |
3 | #include <stdio.h> |
4 | #include "order.h" |
5 | |
6 | |
7 | char* statusorder_ToString(openapi_petstore_order_STATUS_e status) { |
8 | char* statusArray[] = { "NULL", "placed", "approved", "delivered" }; |
9 | return statusArray[status]; |
10 | } |
11 | |
12 | openapi_petstore_order_STATUS_e statusorder_FromString(char* status){ |
13 | int stringToReturn = 0; |
14 | char *statusArray[] = { "NULL", "placed", "approved", "delivered" }; |
15 | size_t sizeofArray = sizeof(statusArray) / sizeof(statusArray[0]); |
16 | while(stringToReturn < sizeofArray) { |
17 | if(strcmp(status, statusArray[stringToReturn]) == 0) { |
18 | return stringToReturn; |
19 | } |
20 | stringToReturn++; |
21 | } |
22 | return 0; |
23 | } |
24 | |
25 | order_t *order_create( |
26 | long id, |
27 | long pet_id, |
28 | int quantity, |
29 | char *ship_date, |
30 | openapi_petstore_order_STATUS_e status, |
31 | int complete |
32 | ) { |
33 | order_t *order_local_var = malloc(sizeof(order_t)); |
34 | if (!order_local_var) { |
35 | return NULL; |
36 | } |
37 | order_local_var->id = id; |
38 | order_local_var->pet_id = pet_id; |
39 | order_local_var->quantity = quantity; |
40 | order_local_var->ship_date = ship_date; |
41 | order_local_var->status = status; |
42 | order_local_var->complete = complete; |
43 | |
44 | return order_local_var; |
45 | } |
46 | |
47 | |
48 | void order_free(order_t *order) { |
49 | if(NULL == order){ |
50 | return ; |
51 | } |
52 | listEntry_t *listEntry; |
53 | if (order->ship_date) { |
54 | free(order->ship_date); |
55 | order->ship_date = NULL; |
56 | } |
57 | free(order); |
58 | } |
59 | |
60 | cJSON *order_convertToJSON(order_t *order) { |
61 | cJSON *item = cJSON_CreateObject(); |
62 | |
63 | |
64 | if(order->id) { |
65 | if(cJSON_AddNumberToObject(item, "id", order->id) == NULL) { |
66 | goto fail; |
67 | } |
68 | } |
69 | |
70 | |
71 | |
72 | if(order->pet_id) { |
73 | if(cJSON_AddNumberToObject(item, "petId", order->pet_id) == NULL) { |
74 | goto fail; |
75 | } |
76 | } |
77 | |
78 | |
79 | |
80 | if(order->quantity) { |
81 | if(cJSON_AddNumberToObject(item, "quantity", order->quantity) == NULL) { |
82 | goto fail; |
83 | } |
84 | } |
85 | |
86 | |
87 | |
88 | if(order->ship_date) { |
89 | if(cJSON_AddStringToObject(item, "shipDate", order->ship_date) == NULL) { |
90 | goto fail; |
91 | } |
92 | } |
93 | |
94 | |
95 | |
96 | |
97 | if(cJSON_AddStringToObject(item, "status", statusorder_ToString(order->status)) == NULL) |
98 | { |
99 | goto fail; |
100 | } |
101 | |
102 | |
103 | |
104 | |
105 | if(order->complete) { |
106 | if(cJSON_AddBoolToObject(item, "complete", order->complete) == NULL) { |
107 | goto fail; |
108 | } |
109 | } |
110 | |
111 | return item; |
112 | fail: |
113 | if (item) { |
114 | cJSON_Delete(item); |
115 | } |
116 | return NULL; |
117 | } |
118 | |
119 | order_t *order_parseFromJSON(cJSON *orderJSON){ |
120 | |
121 | order_t *order_local_var = NULL; |
122 | |
123 | |
124 | cJSON *id = cJSON_GetObjectItemCaseSensitive(orderJSON, "id"); |
125 | if (id) { |
| |
| |
126 | if(!cJSON_IsNumber(id)) |
127 | { |
128 | goto end; |
129 | } |
130 | } |
131 | |
132 | |
133 | cJSON *pet_id = cJSON_GetObjectItemCaseSensitive(orderJSON, "petId"); |
134 | if (pet_id) { |
| 3 | | Assuming 'pet_id' is null | |
|
| |
135 | if(!cJSON_IsNumber(pet_id)) |
136 | { |
137 | goto end; |
138 | } |
139 | } |
140 | |
141 | |
142 | cJSON *quantity = cJSON_GetObjectItemCaseSensitive(orderJSON, "quantity"); |
143 | if (quantity) { |
| 5 | | Assuming 'quantity' is null | |
|
| |
144 | if(!cJSON_IsNumber(quantity)) |
145 | { |
146 | goto end; |
147 | } |
148 | } |
149 | |
150 | |
151 | cJSON *ship_date = cJSON_GetObjectItemCaseSensitive(orderJSON, "shipDate"); |
152 | if (ship_date) { |
| 7 | | Assuming 'ship_date' is non-null | |
|
| |
153 | if(!cJSON_IsString(ship_date)) |
| 9 | | Assuming the condition is false | |
|
| |
154 | { |
155 | goto end; |
156 | } |
157 | } |
158 | |
159 | |
160 | cJSON *status = cJSON_GetObjectItemCaseSensitive(orderJSON, "status"); |
161 | openapi_petstore_order_STATUS_e statusVariable; |
162 | if (status) { |
| 11 | | Assuming 'status' is null | |
|
| |
163 | if(!cJSON_IsString(status)) |
164 | { |
165 | goto end; |
166 | } |
167 | statusVariable = statusorder_FromString(status->valuestring); |
168 | } |
169 | |
170 | |
171 | cJSON *complete = cJSON_GetObjectItemCaseSensitive(orderJSON, "complete"); |
172 | if (complete) { |
| 13 | | Assuming 'complete' is null | |
|
| |
173 | if(!cJSON_IsBool(complete)) |
174 | { |
175 | goto end; |
176 | } |
177 | } |
178 | |
179 | |
180 | order_local_var = order_create ( |
| |
181 | id ? id->valuedouble : 0, |
| |
182 | pet_id ? pet_id->valuedouble : 0, |
| |
183 | quantity ? quantity->valuedouble : 0, |
| |
184 | ship_date ? strdup(ship_date->valuestring) : NULL, |
| |
| |
185 | status ? statusVariable : -1, |
| |
186 | complete ? complete->valueint : 0 |
| |
187 | ); |
188 | |
189 | return order_local_var; |
190 | end: |
191 | return NULL; |
192 | |
193 | } |