clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name tag.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/tag.c
1 | #include <stdlib.h> |
2 | #include <string.h> |
3 | #include <stdio.h> |
4 | #include "tag.h" |
5 | |
6 | |
7 | |
8 | tag_t *tag_create( |
9 | long id, |
10 | char *name |
11 | ) { |
12 | tag_t *tag_local_var = malloc(sizeof(tag_t)); |
13 | if (!tag_local_var) { |
14 | return NULL; |
15 | } |
16 | tag_local_var->id = id; |
17 | tag_local_var->name = name; |
18 | |
19 | return tag_local_var; |
20 | } |
21 | |
22 | |
23 | void tag_free(tag_t *tag) { |
24 | if(NULL == tag){ |
25 | return ; |
26 | } |
27 | listEntry_t *listEntry; |
28 | if (tag->name) { |
29 | free(tag->name); |
30 | tag->name = NULL; |
31 | } |
32 | free(tag); |
33 | } |
34 | |
35 | cJSON *tag_convertToJSON(tag_t *tag) { |
36 | cJSON *item = cJSON_CreateObject(); |
37 | |
38 | |
39 | if(tag->id) { |
40 | if(cJSON_AddNumberToObject(item, "id", tag->id) == NULL) { |
41 | goto fail; |
42 | } |
43 | } |
44 | |
45 | |
46 | |
47 | if(tag->name) { |
48 | if(cJSON_AddStringToObject(item, "name", tag->name) == NULL) { |
49 | goto fail; |
50 | } |
51 | } |
52 | |
53 | return item; |
54 | fail: |
55 | if (item) { |
56 | cJSON_Delete(item); |
57 | } |
58 | return NULL; |
59 | } |
60 | |
61 | tag_t *tag_parseFromJSON(cJSON *tagJSON){ |
62 | |
63 | tag_t *tag_local_var = NULL; |
64 | |
65 | |
66 | cJSON *id = cJSON_GetObjectItemCaseSensitive(tagJSON, "id"); |
67 | if (id) { |
| |
| |
68 | if(!cJSON_IsNumber(id)) |
69 | { |
70 | goto end; |
71 | } |
72 | } |
73 | |
74 | |
75 | cJSON *name = cJSON_GetObjectItemCaseSensitive(tagJSON, "name"); |
76 | if (name) { |
| 3 | | Assuming 'name' is non-null | |
|
| |
77 | if(!cJSON_IsString(name)) |
| 5 | | Assuming the condition is false | |
|
| |
78 | { |
79 | goto end; |
80 | } |
81 | } |
82 | |
83 | |
84 | tag_local_var = tag_create ( |
| |
85 | id ? id->valuedouble : 0, |
| |
86 | name ? strdup(name->valuestring) : NULL |
| |
| |
87 | ); |
88 | |
89 | return tag_local_var; |
90 | end: |
91 | return NULL; |
92 | |
93 | } |