clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name api_response.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/api_response.c
1 | #include <stdlib.h> |
2 | #include <string.h> |
3 | #include <stdio.h> |
4 | #include "api_response.h" |
5 | |
6 | |
7 | |
8 | api_response_t *api_response_create( |
9 | int code, |
10 | char *type, |
11 | char *message |
12 | ) { |
13 | api_response_t *api_response_local_var = malloc(sizeof(api_response_t)); |
14 | if (!api_response_local_var) { |
15 | return NULL; |
16 | } |
17 | api_response_local_var->code = code; |
18 | api_response_local_var->type = type; |
19 | api_response_local_var->message = message; |
20 | |
21 | return api_response_local_var; |
22 | } |
23 | |
24 | |
25 | void api_response_free(api_response_t *api_response) { |
26 | if(NULL == api_response){ |
27 | return ; |
28 | } |
29 | listEntry_t *listEntry; |
30 | if (api_response->type) { |
31 | free(api_response->type); |
32 | api_response->type = NULL; |
33 | } |
34 | if (api_response->message) { |
35 | free(api_response->message); |
36 | api_response->message = NULL; |
37 | } |
38 | free(api_response); |
39 | } |
40 | |
41 | cJSON *api_response_convertToJSON(api_response_t *api_response) { |
42 | cJSON *item = cJSON_CreateObject(); |
43 | |
44 | |
45 | if(api_response->code) { |
46 | if(cJSON_AddNumberToObject(item, "code", api_response->code) == NULL) { |
47 | goto fail; |
48 | } |
49 | } |
50 | |
51 | |
52 | |
53 | if(api_response->type) { |
54 | if(cJSON_AddStringToObject(item, "type", api_response->type) == NULL) { |
55 | goto fail; |
56 | } |
57 | } |
58 | |
59 | |
60 | |
61 | if(api_response->message) { |
62 | if(cJSON_AddStringToObject(item, "message", api_response->message) == NULL) { |
63 | goto fail; |
64 | } |
65 | } |
66 | |
67 | return item; |
68 | fail: |
69 | if (item) { |
70 | cJSON_Delete(item); |
71 | } |
72 | return NULL; |
73 | } |
74 | |
75 | api_response_t *api_response_parseFromJSON(cJSON *api_responseJSON){ |
76 | |
77 | api_response_t *api_response_local_var = NULL; |
78 | |
79 | |
80 | cJSON *code = cJSON_GetObjectItemCaseSensitive(api_responseJSON, "code"); |
81 | if (code) { |
| |
| |
82 | if(!cJSON_IsNumber(code)) |
83 | { |
84 | goto end; |
85 | } |
86 | } |
87 | |
88 | |
89 | cJSON *type = cJSON_GetObjectItemCaseSensitive(api_responseJSON, "type"); |
90 | if (type) { |
| |
| |
91 | if(!cJSON_IsString(type)) |
92 | { |
93 | goto end; |
94 | } |
95 | } |
96 | |
97 | |
98 | cJSON *message = cJSON_GetObjectItemCaseSensitive(api_responseJSON, "message"); |
99 | if (message) { |
| 5 | | Assuming 'message' is non-null | |
|
| |
100 | if(!cJSON_IsString(message)) |
| 7 | | Assuming the condition is false | |
|
| |
101 | { |
102 | goto end; |
103 | } |
104 | } |
105 | |
106 | |
107 | api_response_local_var = api_response_create ( |
| |
108 | code ? code->valuedouble : 0, |
| |
109 | type ? strdup(type->valuestring) : NULL, |
| |
110 | message ? strdup(message->valuestring) : NULL |
| |
| |
111 | ); |
112 | |
113 | return api_response_local_var; |
114 | end: |
115 | return NULL; |
116 | |
117 | } |