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 common.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=/rootdir/backend/dvi/mdvi-lib -resource-dir /usr/lib/llvm-16/lib/clang/16 -D HAVE_CONFIG_H -I . -I ../../.. -D PIC -internal-isystem /usr/lib/llvm-16/lib/clang/16/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/13/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir=/rootdir/backend/dvi/mdvi-lib -ferror-limit 19 -fgnuc-version=4.2.1 -analyzer-checker deadcode.DeadStores -analyzer-checker alpha.deadcode.UnreachableCode -analyzer-checker alpha.core.CastSize -analyzer-checker alpha.core.CastToStruct -analyzer-checker alpha.core.IdenticalExpr -analyzer-checker alpha.core.SizeofPtr -analyzer-checker alpha.security.ArrayBoundV2 -analyzer-checker alpha.security.MallocOverflow -analyzer-checker alpha.security.ReturnPtrRange -analyzer-checker alpha.unix.SimpleStream -analyzer-checker alpha.unix.cstring.BufferOverlap -analyzer-checker alpha.unix.cstring.NotNullTerminated -analyzer-checker alpha.unix.cstring.OutOfBounds -analyzer-checker alpha.core.FixedAddr -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /rootdir/html-report/2024-02-17-123621-54189-1 -x c common.c
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | #include <config.h> |
20 | #include <stdlib.h> |
21 | #include <string.h> |
22 | |
23 | #include "common.h" |
24 | |
25 | long fsgetn(FILE *p, size_t n) |
26 | { |
27 | long v; |
28 | |
29 | v = fgetbyte(p); |
30 | if(v & 0x80) |
31 | v -= 0x100; |
32 | while(--n > 0) |
33 | v = (v << 8) | fgetbyte(p); |
34 | return v; |
35 | } |
36 | |
37 | Ulong fugetn(FILE *p, size_t n) |
38 | { |
39 | Ulong v; |
40 | |
41 | v = fgetbyte(p); |
42 | while(--n > 0) |
43 | v = (v << 8) | fgetbyte(p); |
44 | return v; |
45 | } |
46 | |
47 | long msgetn(const Uchar *p, size_t n) |
48 | { |
49 | long v = (long)*p++; |
50 | |
51 | if(v & 0x80) |
52 | v -= 0x100; |
53 | while(--n > 0) |
54 | v = (v << 8) | *p++; |
55 | return v; |
56 | } |
57 | |
58 | Ulong mugetn(const Uchar *p, size_t n) |
59 | { |
60 | Ulong v = (Ulong)*p++; |
61 | |
62 | while(--n > 0) |
63 | v = (v << 8) | *p++; |
64 | return v; |
65 | } |
66 | |
67 | char *read_string(FILE *in, int s, char *buffer, size_t len) |
68 | { |
69 | int n; |
70 | char *str; |
71 | |
72 | n = fugetn(in, s ? s : 1); |
73 | if((str = buffer) == NULL || n + 1 > len) |
74 | str = mdvi_malloc(n + 1); |
75 | if(fread(str, 1, n, in) != n) { |
76 | if(str != buffer) mdvi_free(str); |
77 | return NULL; |
78 | } |
79 | str[n] = 0; |
80 | return str; |
81 | } |
82 | |
83 | size_t read_bcpl(FILE *in, char *buffer, size_t maxlen, size_t wanted) |
84 | { |
85 | size_t i; |
86 | |
87 | i = (int)fuget1(in); |
88 | if(maxlen && i > maxlen) |
89 | i = maxlen; |
90 | if(fread(buffer, i, 1, in) != 1) |
91 | return -1; |
92 | buffer[i] = '\0'; |
93 | while(wanted-- > i) |
94 | (void)fgetc(in); |
95 | return i; |
96 | } |
97 | |
98 | char *read_alloc_bcpl(FILE *in, size_t maxlen, size_t *size) |
99 | { |
100 | size_t i; |
101 | char *buffer; |
102 | |
103 | i = (size_t)fuget1(in); |
104 | if(maxlen && i > maxlen) |
105 | i = maxlen; |
106 | buffer = (char *)malloc(i + 1); |
107 | if(buffer == NULL) |
108 | return NULL; |
109 | if(fread(buffer, i, 1, in) != 1) { |
110 | free(buffer); |
111 | return NULL; |
112 | } |
113 | buffer[i] = '\0'; |
114 | if(size) *size = i; |
115 | return buffer; |
116 | } |
117 | |
118 | |
119 | |
120 | void buff_free(Buffer *buf) |
121 | { |
122 | if(buf->data) |
123 | mdvi_free(buf->data); |
124 | buff_init(buf); |
125 | } |
126 | |
127 | void buff_init(Buffer *buf) |
128 | { |
129 | buf->data = NULL; |
130 | buf->size = 0; |
131 | buf->length = 0; |
132 | } |
133 | |
134 | size_t buff_add(Buffer *buf, const char *data, size_t len) |
135 | { |
136 | if(!len && data) |
| |
| |
| 3 | | Assuming pointer value is null | |
|
| |
137 | len = strlen(data); |
138 | if(buf->length + len + 1 > buf->size) { |
| 5 | | Assuming the condition is false | |
|
| |
139 | buf->size = buf->length + len + 256; |
140 | buf->data = mdvi_realloc(buf->data, buf->size); |
141 | } |
142 | memcpy(buf->data + buf->length, data, len); |
| 7 | | Null pointer passed to 2nd parameter expecting 'nonnull' |
|
143 | buf->length += len; |
144 | return buf->length; |
145 | } |
146 | |
147 | char *buff_gets(Buffer *buf, size_t *length) |
148 | { |
149 | char *ptr; |
150 | char *ret; |
151 | size_t len; |
152 | |
153 | ptr = strchr(buf->data, '\n'); |
154 | if(ptr == NULL) |
155 | return NULL; |
156 | ptr++; |
157 | len = ptr - buf->data; |
158 | ret = mdvi_malloc(len + 1); |
159 | if(len > 0) { |
160 | memcpy(ret, buf->data, len); |
161 | memmove(buf->data, buf->data + len, buf->length - len); |
162 | buf->length -= len; |
163 | } |
164 | ret[len] = 0; |
165 | if(length) *length = len; |
166 | return ret; |
167 | } |
168 | |