Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/openssl/src/crypto/bio/b_print.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* | - | ||||||||||||||||||
2 | * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. | - | ||||||||||||||||||
3 | * | - | ||||||||||||||||||
4 | * Licensed under the OpenSSL license (the "License"). You may not use | - | ||||||||||||||||||
5 | * this file except in compliance with the License. You can obtain a copy | - | ||||||||||||||||||
6 | * in the file LICENSE in the source distribution or at | - | ||||||||||||||||||
7 | * https://www.openssl.org/source/license.html | - | ||||||||||||||||||
8 | */ | - | ||||||||||||||||||
9 | - | |||||||||||||||||||
10 | #include <stdio.h> | - | ||||||||||||||||||
11 | #include <string.h> | - | ||||||||||||||||||
12 | #include "internal/cryptlib.h" | - | ||||||||||||||||||
13 | #include "internal/ctype.h" | - | ||||||||||||||||||
14 | #include "internal/numbers.h" | - | ||||||||||||||||||
15 | #include <openssl/bio.h> | - | ||||||||||||||||||
16 | - | |||||||||||||||||||
17 | /* | - | ||||||||||||||||||
18 | * Copyright Patrick Powell 1995 | - | ||||||||||||||||||
19 | * This code is based on code written by Patrick Powell <papowell@astart.com> | - | ||||||||||||||||||
20 | * It may be used for any purpose as long as this notice remains intact | - | ||||||||||||||||||
21 | * on all source code distributions. | - | ||||||||||||||||||
22 | */ | - | ||||||||||||||||||
23 | - | |||||||||||||||||||
24 | #ifdef HAVE_LONG_DOUBLE | - | ||||||||||||||||||
25 | # define LDOUBLE long double | - | ||||||||||||||||||
26 | #else | - | ||||||||||||||||||
27 | # define LDOUBLE double | - | ||||||||||||||||||
28 | #endif | - | ||||||||||||||||||
29 | - | |||||||||||||||||||
30 | static int fmtstr(char **, char **, size_t *, size_t *, | - | ||||||||||||||||||
31 | const char *, int, int, int); | - | ||||||||||||||||||
32 | static int fmtint(char **, char **, size_t *, size_t *, | - | ||||||||||||||||||
33 | int64_t, int, int, int, int); | - | ||||||||||||||||||
34 | static int fmtfp(char **, char **, size_t *, size_t *, | - | ||||||||||||||||||
35 | LDOUBLE, int, int, int, int); | - | ||||||||||||||||||
36 | static int doapr_outch(char **, char **, size_t *, size_t *, int); | - | ||||||||||||||||||
37 | static int _dopr(char **sbuffer, char **buffer, | - | ||||||||||||||||||
38 | size_t *maxlen, size_t *retlen, int *truncated, | - | ||||||||||||||||||
39 | const char *format, va_list args); | - | ||||||||||||||||||
40 | - | |||||||||||||||||||
41 | /* format read states */ | - | ||||||||||||||||||
42 | #define DP_S_DEFAULT 0 | - | ||||||||||||||||||
43 | #define DP_S_FLAGS 1 | - | ||||||||||||||||||
44 | #define DP_S_MIN 2 | - | ||||||||||||||||||
45 | #define DP_S_DOT 3 | - | ||||||||||||||||||
46 | #define DP_S_MAX 4 | - | ||||||||||||||||||
47 | #define DP_S_MOD 5 | - | ||||||||||||||||||
48 | #define DP_S_CONV 6 | - | ||||||||||||||||||
49 | #define DP_S_DONE 7 | - | ||||||||||||||||||
50 | - | |||||||||||||||||||
51 | /* format flags - Bits */ | - | ||||||||||||||||||
52 | /* left-aligned padding */ | - | ||||||||||||||||||
53 | #define DP_F_MINUS (1 << 0) | - | ||||||||||||||||||
54 | /* print an explicit '+' for a value with positive sign */ | - | ||||||||||||||||||
55 | #define DP_F_PLUS (1 << 1) | - | ||||||||||||||||||
56 | /* print an explicit ' ' for a value with positive sign */ | - | ||||||||||||||||||
57 | #define DP_F_SPACE (1 << 2) | - | ||||||||||||||||||
58 | /* print 0/0x prefix for octal/hex and decimal point for floating point */ | - | ||||||||||||||||||
59 | #define DP_F_NUM (1 << 3) | - | ||||||||||||||||||
60 | /* print leading zeroes */ | - | ||||||||||||||||||
61 | #define DP_F_ZERO (1 << 4) | - | ||||||||||||||||||
62 | /* print HEX in UPPPERcase */ | - | ||||||||||||||||||
63 | #define DP_F_UP (1 << 5) | - | ||||||||||||||||||
64 | /* treat value as unsigned */ | - | ||||||||||||||||||
65 | #define DP_F_UNSIGNED (1 << 6) | - | ||||||||||||||||||
66 | - | |||||||||||||||||||
67 | /* conversion flags */ | - | ||||||||||||||||||
68 | #define DP_C_SHORT 1 | - | ||||||||||||||||||
69 | #define DP_C_LONG 2 | - | ||||||||||||||||||
70 | #define DP_C_LDOUBLE 3 | - | ||||||||||||||||||
71 | #define DP_C_LLONG 4 | - | ||||||||||||||||||
72 | #define DP_C_SIZE 5 | - | ||||||||||||||||||
73 | - | |||||||||||||||||||
74 | /* Floating point formats */ | - | ||||||||||||||||||
75 | #define F_FORMAT 0 | - | ||||||||||||||||||
76 | #define E_FORMAT 1 | - | ||||||||||||||||||
77 | #define G_FORMAT 2 | - | ||||||||||||||||||
78 | - | |||||||||||||||||||
79 | /* some handy macros */ | - | ||||||||||||||||||
80 | #define char_to_int(p) (p - '0') | - | ||||||||||||||||||
81 | #define OSSL_MAX(p,q) ((p >= q) ? p : q) | - | ||||||||||||||||||
82 | - | |||||||||||||||||||
83 | static int | - | ||||||||||||||||||
84 | _dopr(char **sbuffer, | - | ||||||||||||||||||
85 | char **buffer, | - | ||||||||||||||||||
86 | size_t *maxlen, | - | ||||||||||||||||||
87 | size_t *retlen, int *truncated, const char *format, va_list args) | - | ||||||||||||||||||
88 | { | - | ||||||||||||||||||
89 | char ch; | - | ||||||||||||||||||
90 | int64_t value; | - | ||||||||||||||||||
91 | LDOUBLE fvalue; | - | ||||||||||||||||||
92 | char *strvalue; | - | ||||||||||||||||||
93 | int min; | - | ||||||||||||||||||
94 | int max; | - | ||||||||||||||||||
95 | int state; | - | ||||||||||||||||||
96 | int flags; | - | ||||||||||||||||||
97 | int cflags; | - | ||||||||||||||||||
98 | size_t currlen; | - | ||||||||||||||||||
99 | - | |||||||||||||||||||
100 | state = DP_S_DEFAULT; | - | ||||||||||||||||||
101 | flags = currlen = cflags = min = 0; | - | ||||||||||||||||||
102 | max = -1; | - | ||||||||||||||||||
103 | ch = *format++; | - | ||||||||||||||||||
104 | - | |||||||||||||||||||
105 | while (state != DP_S_DONE) {
| 8876302-119848483 | ||||||||||||||||||
106 | if (ch == '\0' || (buffer == NULL && currlen >= *maxlen))
| 0-110972181 | ||||||||||||||||||
107 | state = DP_S_DONE; executed 8876302 times by 12 tests: state = 7; Executed by:
| 8876302 | ||||||||||||||||||
108 | - | |||||||||||||||||||
109 | switch (state) { | - | ||||||||||||||||||
110 | case DP_S_DEFAULT: executed 33570494 times by 12 tests: case 0: Executed by:
| 33570494 | ||||||||||||||||||
111 | if (ch == '%')
| 12102492-21468002 | ||||||||||||||||||
112 | state = DP_S_FLAGS; executed 12102492 times by 12 tests: state = 1; Executed by:
| 12102492 | ||||||||||||||||||
113 | else | - | ||||||||||||||||||
114 | if (!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch))
| 0-21468002 | ||||||||||||||||||
115 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
116 | ch = *format++; | - | ||||||||||||||||||
117 | break; executed 33570494 times by 12 tests: break; Executed by:
| 33570494 | ||||||||||||||||||
118 | case DP_S_FLAGS: executed 18525771 times by 12 tests: case 1: Executed by:
| 18525771 | ||||||||||||||||||
119 | switch (ch) { | - | ||||||||||||||||||
120 | case '-': executed 2857542 times by 1 test: case '-': Executed by:
| 2857542 | ||||||||||||||||||
121 | flags |= DP_F_MINUS; | - | ||||||||||||||||||
122 | ch = *format++; | - | ||||||||||||||||||
123 | break; executed 2857542 times by 1 test: break; Executed by:
| 2857542 | ||||||||||||||||||
124 | case '+': never executed: case '+': | 0 | ||||||||||||||||||
125 | flags |= DP_F_PLUS; | - | ||||||||||||||||||
126 | ch = *format++; | - | ||||||||||||||||||
127 | break; never executed: break; | 0 | ||||||||||||||||||
128 | case ' ': executed 216 times by 1 test: case ' ': Executed by:
| 216 | ||||||||||||||||||
129 | flags |= DP_F_SPACE; | - | ||||||||||||||||||
130 | ch = *format++; | - | ||||||||||||||||||
131 | break; executed 216 times by 1 test: break; Executed by:
| 216 | ||||||||||||||||||
132 | case '#': never executed: case '#': | 0 | ||||||||||||||||||
133 | flags |= DP_F_NUM; | - | ||||||||||||||||||
134 | ch = *format++; | - | ||||||||||||||||||
135 | break; never executed: break; | 0 | ||||||||||||||||||
136 | case '0': executed 3565521 times by 1 test: case '0': Executed by:
| 3565521 | ||||||||||||||||||
137 | flags |= DP_F_ZERO; | - | ||||||||||||||||||
138 | ch = *format++; | - | ||||||||||||||||||
139 | break; executed 3565521 times by 1 test: break; Executed by:
| 3565521 | ||||||||||||||||||
140 | default: executed 12102492 times by 12 tests: default: Executed by:
| 12102492 | ||||||||||||||||||
141 | state = DP_S_MIN; | - | ||||||||||||||||||
142 | break; executed 12102492 times by 12 tests: break; Executed by:
| 12102492 | ||||||||||||||||||
143 | } | - | ||||||||||||||||||
144 | break; executed 18525771 times by 12 tests: break; Executed by:
| 18525771 | ||||||||||||||||||
145 | case DP_S_MIN: executed 22556335 times by 12 tests: case 2: Executed by:
| 22556335 | ||||||||||||||||||
146 | if (ossl_isdigit(ch)) {
| 10453843-12102492 | ||||||||||||||||||
147 | min = 10 * min + char_to_int(ch); | - | ||||||||||||||||||
148 | ch = *format++; | - | ||||||||||||||||||
149 | } else if (ch == '*') { executed 10453843 times by 1 test: end of block Executed by:
| 304477-11798015 | ||||||||||||||||||
150 | min = va_arg(args, int); | - | ||||||||||||||||||
151 | ch = *format++; | - | ||||||||||||||||||
152 | state = DP_S_DOT; | - | ||||||||||||||||||
153 | } else executed 304477 times by 12 tests: end of block Executed by:
| 304477 | ||||||||||||||||||
154 | state = DP_S_DOT; executed 11798015 times by 12 tests: state = 3; Executed by:
| 11798015 | ||||||||||||||||||
155 | break; executed 22556335 times by 12 tests: break; Executed by:
| 22556335 | ||||||||||||||||||
156 | case DP_S_DOT: executed 12102492 times by 12 tests: case 3: Executed by:
| 12102492 | ||||||||||||||||||
157 | if (ch == '.') {
| 7123-12095369 | ||||||||||||||||||
158 | state = DP_S_MAX; | - | ||||||||||||||||||
159 | ch = *format++; | - | ||||||||||||||||||
160 | } else executed 7123 times by 1 test: end of block Executed by:
| 7123 | ||||||||||||||||||
161 | state = DP_S_MOD; executed 12095369 times by 12 tests: state = 5; Executed by:
| 12095369 | ||||||||||||||||||
162 | break; executed 12102492 times by 12 tests: break; Executed by:
| 12102492 | ||||||||||||||||||
163 | case DP_S_MAX: executed 12105 times by 1 test: case 4: Executed by:
| 12105 | ||||||||||||||||||
164 | if (ossl_isdigit(ch)) {
| 4982-7123 | ||||||||||||||||||
165 | if (max < 0)
| 2338-2644 | ||||||||||||||||||
166 | max = 0; executed 2644 times by 1 test: max = 0; Executed by:
| 2644 | ||||||||||||||||||
167 | max = 10 * max + char_to_int(ch); | - | ||||||||||||||||||
168 | ch = *format++; | - | ||||||||||||||||||
169 | } else if (ch == '*') { executed 4982 times by 1 test: end of block Executed by:
| 2644-4982 | ||||||||||||||||||
170 | max = va_arg(args, int); | - | ||||||||||||||||||
171 | ch = *format++; | - | ||||||||||||||||||
172 | state = DP_S_MOD; | - | ||||||||||||||||||
173 | } else executed 4479 times by 1 test: end of block Executed by:
| 4479 | ||||||||||||||||||
174 | state = DP_S_MOD; executed 2644 times by 1 test: state = 5; Executed by:
| 2644 | ||||||||||||||||||
175 | break; executed 12105 times by 1 test: break; Executed by:
| 12105 | ||||||||||||||||||
176 | case DP_S_MOD: executed 12102492 times by 12 tests: case 5: Executed by:
| 12102492 | ||||||||||||||||||
177 | switch (ch) { | - | ||||||||||||||||||
178 | case 'h': never executed: case 'h': | 0 | ||||||||||||||||||
179 | cflags = DP_C_SHORT; | - | ||||||||||||||||||
180 | ch = *format++; | - | ||||||||||||||||||
181 | break; never executed: break; | 0 | ||||||||||||||||||
182 | case 'l': executed 4416542 times by 2 tests: case 'l': Executed by:
| 4416542 | ||||||||||||||||||
183 | if (*format == 'l') {
| 0-4416542 | ||||||||||||||||||
184 | cflags = DP_C_LLONG; | - | ||||||||||||||||||
185 | format++; | - | ||||||||||||||||||
186 | } else never executed: end of block | 0 | ||||||||||||||||||
187 | cflags = DP_C_LONG; executed 4416542 times by 2 tests: cflags = 2; Executed by:
| 4416542 | ||||||||||||||||||
188 | ch = *format++; | - | ||||||||||||||||||
189 | break; executed 4416542 times by 2 tests: break; Executed by:
| 4416542 | ||||||||||||||||||
190 | case 'q': never executed: case 'q': | 0 | ||||||||||||||||||
191 | case 'j': executed 432 times by 1 test: case 'j': Executed by:
| 432 | ||||||||||||||||||
192 | cflags = DP_C_LLONG; | - | ||||||||||||||||||
193 | ch = *format++; | - | ||||||||||||||||||
194 | break; executed 432 times by 1 test: break; Executed by:
| 432 | ||||||||||||||||||
195 | case 'L': never executed: case 'L': | 0 | ||||||||||||||||||
196 | cflags = DP_C_LDOUBLE; | - | ||||||||||||||||||
197 | ch = *format++; | - | ||||||||||||||||||
198 | break; never executed: break; | 0 | ||||||||||||||||||
199 | case 'z': executed 17 times by 1 test: case 'z': Executed by:
| 17 | ||||||||||||||||||
200 | cflags = DP_C_SIZE; | - | ||||||||||||||||||
201 | ch = *format++; | - | ||||||||||||||||||
202 | break; executed 17 times by 1 test: break; Executed by:
| 17 | ||||||||||||||||||
203 | default: executed 7685501 times by 12 tests: default: Executed by:
| 7685501 | ||||||||||||||||||
204 | break; executed 7685501 times by 12 tests: break; Executed by:
| 7685501 | ||||||||||||||||||
205 | } | - | ||||||||||||||||||
206 | state = DP_S_CONV; | - | ||||||||||||||||||
207 | break; executed 12102492 times by 12 tests: break; Executed by:
| 12102492 | ||||||||||||||||||
208 | case DP_S_CONV: executed 12102492 times by 12 tests: case 6: Executed by:
| 12102492 | ||||||||||||||||||
209 | switch (ch) { | - | ||||||||||||||||||
210 | case 'd': executed 5641261 times by 11 tests: case 'd': Executed by:
| 5641261 | ||||||||||||||||||
211 | case 'i': executed 6 times by 1 test: case 'i': Executed by:
| 6 | ||||||||||||||||||
212 | switch (cflags) { | - | ||||||||||||||||||
213 | case DP_C_SHORT: never executed: case 1: | 0 | ||||||||||||||||||
214 | value = (short int)va_arg(args, int); | - | ||||||||||||||||||
215 | break; never executed: break; | 0 | ||||||||||||||||||
216 | case DP_C_LONG: executed 3987970 times by 1 test: case 2: Executed by:
| 3987970 | ||||||||||||||||||
217 | value = va_arg(args, long int); | - | ||||||||||||||||||
218 | break; executed 3987970 times by 1 test: break; Executed by:
| 3987970 | ||||||||||||||||||
219 | case DP_C_LLONG: executed 29 times by 1 test: case 4: Executed by:
| 29 | ||||||||||||||||||
220 | value = va_arg(args, int64_t); | - | ||||||||||||||||||
221 | break; executed 29 times by 1 test: break; Executed by:
| 29 | ||||||||||||||||||
222 | case DP_C_SIZE: executed 2 times by 1 test: case 5: Executed by:
| 2 | ||||||||||||||||||
223 | value = va_arg(args, ossl_ssize_t); | - | ||||||||||||||||||
224 | break; executed 2 times by 1 test: break; Executed by:
| 2 | ||||||||||||||||||
225 | default: executed 1653266 times by 11 tests: default: Executed by:
| 1653266 | ||||||||||||||||||
226 | value = va_arg(args, int); | - | ||||||||||||||||||
227 | break; executed 1653266 times by 11 tests: break; Executed by:
| 1653266 | ||||||||||||||||||
228 | } | - | ||||||||||||||||||
229 | if (!fmtint(sbuffer, buffer, &currlen, maxlen, value, 10, min,
| 0-5641267 | ||||||||||||||||||
230 | max, flags))
| 0-5641267 | ||||||||||||||||||
231 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
232 | break; executed 5641267 times by 11 tests: break; Executed by:
| 5641267 | ||||||||||||||||||
233 | case 'X': executed 3015980 times by 1 test: case 'X': Executed by:
| 3015980 | ||||||||||||||||||
234 | flags |= DP_F_UP; | - | ||||||||||||||||||
235 | /* FALLTHROUGH */ | - | ||||||||||||||||||
236 | case 'x': code before this statement executed 3015980 times by 1 test: case 'x': Executed by:
executed 466992 times by 1 test: case 'x': Executed by:
| 466992-3015980 | ||||||||||||||||||
237 | case 'o': never executed: case 'o': | 0 | ||||||||||||||||||
238 | case 'u': executed 421034 times by 2 tests: case 'u': Executed by:
| 421034 | ||||||||||||||||||
239 | flags |= DP_F_UNSIGNED; | - | ||||||||||||||||||
240 | switch (cflags) { | - | ||||||||||||||||||
241 | case DP_C_SHORT: never executed: case 1: | 0 | ||||||||||||||||||
242 | value = (unsigned short int)va_arg(args, unsigned int); | - | ||||||||||||||||||
243 | break; never executed: break; | 0 | ||||||||||||||||||
244 | case DP_C_LONG: executed 428572 times by 2 tests: case 2: Executed by:
| 428572 | ||||||||||||||||||
245 | value = va_arg(args, unsigned long int); | - | ||||||||||||||||||
246 | break; executed 428572 times by 2 tests: break; Executed by:
| 428572 | ||||||||||||||||||
247 | case DP_C_LLONG: executed 403 times by 1 test: case 4: Executed by:
| 403 | ||||||||||||||||||
248 | value = va_arg(args, uint64_t); | - | ||||||||||||||||||
249 | break; executed 403 times by 1 test: break; Executed by:
| 403 | ||||||||||||||||||
250 | case DP_C_SIZE: executed 15 times by 1 test: case 5: Executed by:
| 15 | ||||||||||||||||||
251 | value = va_arg(args, size_t); | - | ||||||||||||||||||
252 | break; executed 15 times by 1 test: break; Executed by:
| 15 | ||||||||||||||||||
253 | default: executed 3475016 times by 1 test: default: Executed by:
| 3475016 | ||||||||||||||||||
254 | value = va_arg(args, unsigned int); | - | ||||||||||||||||||
255 | break; executed 3475016 times by 1 test: break; Executed by:
| 3475016 | ||||||||||||||||||
256 | } | - | ||||||||||||||||||
257 | if (!fmtint(sbuffer, buffer, &currlen, maxlen, value,
| 0-3904006 | ||||||||||||||||||
258 | ch == 'o' ? 8 : (ch == 'u' ? 10 : 16),
| 0-3904006 | ||||||||||||||||||
259 | min, max, flags))
| 0-3904006 | ||||||||||||||||||
260 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
261 | break; executed 3904006 times by 2 tests: break; Executed by:
| 3904006 | ||||||||||||||||||
262 | case 'f': executed 77 times by 1 test: case 'f': Executed by:
| 77 | ||||||||||||||||||
263 | if (cflags == DP_C_LDOUBLE)
| 0-77 | ||||||||||||||||||
264 | fvalue = va_arg(args, LDOUBLE); never executed: fvalue = __builtin_va_arg( args , double ) ; | 0 | ||||||||||||||||||
265 | else | - | ||||||||||||||||||
266 | fvalue = va_arg(args, double); executed 77 times by 1 test: fvalue = __builtin_va_arg( args , double ) ; Executed by:
| 77 | ||||||||||||||||||
267 | if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,
| 1-76 | ||||||||||||||||||
268 | flags, F_FORMAT))
| 1-76 | ||||||||||||||||||
269 | return 0; executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||||||||
270 | break; executed 76 times by 1 test: break; Executed by:
| 76 | ||||||||||||||||||
271 | case 'E': executed 70 times by 1 test: case 'E': Executed by:
| 70 | ||||||||||||||||||
272 | flags |= DP_F_UP; | - | ||||||||||||||||||
273 | /* fall thru */ | - | ||||||||||||||||||
274 | case 'e': code before this statement executed 70 times by 1 test: case 'e': Executed by:
executed 70 times by 1 test: case 'e': Executed by:
| 70 | ||||||||||||||||||
275 | if (cflags == DP_C_LDOUBLE)
| 0-140 | ||||||||||||||||||
276 | fvalue = va_arg(args, LDOUBLE); never executed: fvalue = __builtin_va_arg( args , double ) ; | 0 | ||||||||||||||||||
277 | else | - | ||||||||||||||||||
278 | fvalue = va_arg(args, double); executed 140 times by 1 test: fvalue = __builtin_va_arg( args , double ) ; Executed by:
| 140 | ||||||||||||||||||
279 | if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,
| 0-140 | ||||||||||||||||||
280 | flags, E_FORMAT))
| 0-140 | ||||||||||||||||||
281 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
282 | break; executed 140 times by 1 test: break; Executed by:
| 140 | ||||||||||||||||||
283 | case 'G': executed 70 times by 1 test: case 'G': Executed by:
| 70 | ||||||||||||||||||
284 | flags |= DP_F_UP; | - | ||||||||||||||||||
285 | /* fall thru */ | - | ||||||||||||||||||
286 | case 'g': code before this statement executed 70 times by 1 test: case 'g': Executed by:
executed 70 times by 1 test: case 'g': Executed by:
| 70 | ||||||||||||||||||
287 | if (cflags == DP_C_LDOUBLE)
| 0-140 | ||||||||||||||||||
288 | fvalue = va_arg(args, LDOUBLE); never executed: fvalue = __builtin_va_arg( args , double ) ; | 0 | ||||||||||||||||||
289 | else | - | ||||||||||||||||||
290 | fvalue = va_arg(args, double); executed 140 times by 1 test: fvalue = __builtin_va_arg( args , double ) ; Executed by:
| 140 | ||||||||||||||||||
291 | if (!fmtfp(sbuffer, buffer, &currlen, maxlen, fvalue, min, max,
| 0-140 | ||||||||||||||||||
292 | flags, G_FORMAT))
| 0-140 | ||||||||||||||||||
293 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
294 | break; executed 140 times by 1 test: break; Executed by:
| 140 | ||||||||||||||||||
295 | case 'c': executed 84071 times by 1 test: case 'c': Executed by:
| 84071 | ||||||||||||||||||
296 | if (!doapr_outch(sbuffer, buffer, &currlen, maxlen,
| 0-84071 | ||||||||||||||||||
297 | va_arg(args, int)))
| 0-84071 | ||||||||||||||||||
298 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
299 | break; executed 84071 times by 1 test: break; Executed by:
| 84071 | ||||||||||||||||||
300 | case 's': executed 2472428 times by 12 tests: case 's': Executed by:
| 2472428 | ||||||||||||||||||
301 | strvalue = va_arg(args, char *); | - | ||||||||||||||||||
302 | if (max < 0) {
| 6817-2465611 | ||||||||||||||||||
303 | if (buffer)
| 44630-2420981 | ||||||||||||||||||
304 | max = INT_MAX; executed 2420981 times by 12 tests: max = 0x7fffffff; Executed by:
| 2420981 | ||||||||||||||||||
305 | else | - | ||||||||||||||||||
306 | max = *maxlen; executed 44630 times by 1 test: max = *maxlen; Executed by:
| 44630 | ||||||||||||||||||
307 | } | - | ||||||||||||||||||
308 | if (!fmtstr(sbuffer, buffer, &currlen, maxlen, strvalue,
| 0-2472428 | ||||||||||||||||||
309 | flags, min, max))
| 0-2472428 | ||||||||||||||||||
310 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
311 | break; executed 2472428 times by 12 tests: break; Executed by:
| 2472428 | ||||||||||||||||||
312 | case 'p': executed 13 times by 1 test: case 'p': Executed by:
| 13 | ||||||||||||||||||
313 | value = (size_t)va_arg(args, void *); | - | ||||||||||||||||||
314 | if (!fmtint(sbuffer, buffer, &currlen, maxlen,
| 0-13 | ||||||||||||||||||
315 | value, 16, min, max, flags | DP_F_NUM))
| 0-13 | ||||||||||||||||||
316 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
317 | break; executed 13 times by 1 test: break; Executed by:
| 13 | ||||||||||||||||||
318 | case 'n': never executed: case 'n': | 0 | ||||||||||||||||||
319 | { | - | ||||||||||||||||||
320 | int *num; | - | ||||||||||||||||||
321 | num = va_arg(args, int *); | - | ||||||||||||||||||
322 | *num = currlen; | - | ||||||||||||||||||
323 | } | - | ||||||||||||||||||
324 | break; never executed: break; | 0 | ||||||||||||||||||
325 | case '%': executed 350 times by 1 test: case '%': Executed by:
| 350 | ||||||||||||||||||
326 | if (!doapr_outch(sbuffer, buffer, &currlen, maxlen, ch))
| 0-350 | ||||||||||||||||||
327 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
328 | break; executed 350 times by 1 test: break; Executed by:
| 350 | ||||||||||||||||||
329 | case 'w': never executed: case 'w': | 0 | ||||||||||||||||||
330 | /* not supported yet, treat as next char */ | - | ||||||||||||||||||
331 | ch = *format++; | - | ||||||||||||||||||
332 | break; never executed: break; | 0 | ||||||||||||||||||
333 | default: never executed: default: | 0 | ||||||||||||||||||
334 | /* unknown, skip */ | - | ||||||||||||||||||
335 | break; never executed: break; | 0 | ||||||||||||||||||
336 | } | - | ||||||||||||||||||
337 | ch = *format++; | - | ||||||||||||||||||
338 | state = DP_S_DEFAULT; | - | ||||||||||||||||||
339 | flags = cflags = min = 0; | - | ||||||||||||||||||
340 | max = -1; | - | ||||||||||||||||||
341 | break; executed 12102491 times by 12 tests: break; Executed by:
| 12102491 | ||||||||||||||||||
342 | case DP_S_DONE: executed 8876302 times by 12 tests: case 7: Executed by:
| 8876302 | ||||||||||||||||||
343 | break; executed 8876302 times by 12 tests: break; Executed by:
| 8876302 | ||||||||||||||||||
344 | default: never executed: default: | 0 | ||||||||||||||||||
345 | break; never executed: break; | 0 | ||||||||||||||||||
346 | } | - | ||||||||||||||||||
347 | } | - | ||||||||||||||||||
348 | /* | - | ||||||||||||||||||
349 | * We have to truncate if there is no dynamic buffer and we have filled the | - | ||||||||||||||||||
350 | * static buffer. | - | ||||||||||||||||||
351 | */ | - | ||||||||||||||||||
352 | if (buffer == NULL) {
| 693766-8182536 | ||||||||||||||||||
353 | *truncated = (currlen > *maxlen - 1); | - | ||||||||||||||||||
354 | if (*truncated)
| 0-693766 | ||||||||||||||||||
355 | currlen = *maxlen - 1; never executed: currlen = *maxlen - 1; | 0 | ||||||||||||||||||
356 | } executed 693766 times by 1 test: end of block Executed by:
| 693766 | ||||||||||||||||||
357 | if (!doapr_outch(sbuffer, buffer, &currlen, maxlen, '\0'))
| 0-8876302 | ||||||||||||||||||
358 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
359 | *retlen = currlen - 1; | - | ||||||||||||||||||
360 | return 1; executed 8876302 times by 12 tests: return 1; Executed by:
| 8876302 | ||||||||||||||||||
361 | } | - | ||||||||||||||||||
362 | - | |||||||||||||||||||
363 | static int | - | ||||||||||||||||||
364 | fmtstr(char **sbuffer, | - | ||||||||||||||||||
365 | char **buffer, | - | ||||||||||||||||||
366 | size_t *currlen, | - | ||||||||||||||||||
367 | size_t *maxlen, const char *value, int flags, int min, int max) | - | ||||||||||||||||||
368 | { | - | ||||||||||||||||||
369 | int padlen; | - | ||||||||||||||||||
370 | size_t strln; | - | ||||||||||||||||||
371 | int cnt = 0; | - | ||||||||||||||||||
372 | - | |||||||||||||||||||
373 | if (value == 0)
| 2641-2469787 | ||||||||||||||||||
374 | value = "<NULL>"; executed 2641 times by 1 test: value = "<NULL>"; Executed by:
| 2641 | ||||||||||||||||||
375 | - | |||||||||||||||||||
376 | strln = OPENSSL_strnlen(value, max < 0 ? SIZE_MAX : (size_t)max); | - | ||||||||||||||||||
377 | - | |||||||||||||||||||
378 | padlen = min - strln; | - | ||||||||||||||||||
379 | if (min < 0 || padlen < 0)
| 0-2472428 | ||||||||||||||||||
380 | padlen = 0; executed 573757 times by 12 tests: padlen = 0; Executed by:
| 573757 | ||||||||||||||||||
381 | if (max >= 0) {
| 0-2472428 | ||||||||||||||||||
382 | /* | - | ||||||||||||||||||
383 | * Calculate the maximum output including padding. | - | ||||||||||||||||||
384 | * Make sure max doesn't overflow into negativity | - | ||||||||||||||||||
385 | */ | - | ||||||||||||||||||
386 | if (max < INT_MAX - padlen)
| 51447-2420981 | ||||||||||||||||||
387 | max += padlen; executed 51447 times by 1 test: max += padlen; Executed by:
| 51447 | ||||||||||||||||||
388 | else | - | ||||||||||||||||||
389 | max = INT_MAX; executed 2420981 times by 12 tests: max = 0x7fffffff; Executed by:
| 2420981 | ||||||||||||||||||
390 | } | - | ||||||||||||||||||
391 | if (flags & DP_F_MINUS)
| 1043542-1428886 | ||||||||||||||||||
392 | padlen = -padlen; executed 1428886 times by 1 test: padlen = -padlen; Executed by:
| 1428886 | ||||||||||||||||||
393 | - | |||||||||||||||||||
394 | while ((padlen > 0) && (max < 0 || cnt < max)) {
| 0-4048071 | ||||||||||||||||||
395 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen, ' '))
| 0-4048071 | ||||||||||||||||||
396 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
397 | --padlen; | - | ||||||||||||||||||
398 | ++cnt; | - | ||||||||||||||||||
399 | } executed 4048071 times by 12 tests: end of block Executed by:
| 4048071 | ||||||||||||||||||
400 | while (strln > 0 && (max < 0 || cnt < max)) {
| 0-13566703 | ||||||||||||||||||
401 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen, *value++))
| 0-13566703 | ||||||||||||||||||
402 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
403 | --strln; | - | ||||||||||||||||||
404 | ++cnt; | - | ||||||||||||||||||
405 | } executed 13566703 times by 12 tests: end of block Executed by:
| 13566703 | ||||||||||||||||||
406 | while ((padlen < 0) && (max < 0 || cnt < max)) {
| 0-15300961 | ||||||||||||||||||
407 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen, ' '))
| 0-15300961 | ||||||||||||||||||
408 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
409 | ++padlen; | - | ||||||||||||||||||
410 | ++cnt; | - | ||||||||||||||||||
411 | } executed 15300961 times by 1 test: end of block Executed by:
| 15300961 | ||||||||||||||||||
412 | return 1; executed 2472428 times by 12 tests: return 1; Executed by:
| 2472428 | ||||||||||||||||||
413 | } | - | ||||||||||||||||||
414 | - | |||||||||||||||||||
415 | static int | - | ||||||||||||||||||
416 | fmtint(char **sbuffer, | - | ||||||||||||||||||
417 | char **buffer, | - | ||||||||||||||||||
418 | size_t *currlen, | - | ||||||||||||||||||
419 | size_t *maxlen, int64_t value, int base, int min, int max, int flags) | - | ||||||||||||||||||
420 | { | - | ||||||||||||||||||
421 | int signvalue = 0; | - | ||||||||||||||||||
422 | const char *prefix = ""; | - | ||||||||||||||||||
423 | uint64_t uvalue; | - | ||||||||||||||||||
424 | char convert[DECIMAL_SIZE(value) + 3]; | - | ||||||||||||||||||
425 | int place = 0; | - | ||||||||||||||||||
426 | int spadlen = 0; | - | ||||||||||||||||||
427 | int zpadlen = 0; | - | ||||||||||||||||||
428 | int caps = 0; | - | ||||||||||||||||||
429 | - | |||||||||||||||||||
430 | if (max < 0)
| 0-9545286 | ||||||||||||||||||
431 | max = 0; executed 9545286 times by 11 tests: max = 0; Executed by:
| 9545286 | ||||||||||||||||||
432 | uvalue = value; | - | ||||||||||||||||||
433 | if (!(flags & DP_F_UNSIGNED)) {
| 3904006-5641280 | ||||||||||||||||||
434 | if (value < 0) {
| 676-5640604 | ||||||||||||||||||
435 | signvalue = '-'; | - | ||||||||||||||||||
436 | uvalue = 0 - (uint64_t)value; | - | ||||||||||||||||||
437 | } else if (flags & DP_F_PLUS) executed 676 times by 1 test: end of block Executed by:
| 0-5640604 | ||||||||||||||||||
438 | signvalue = '+'; never executed: signvalue = '+'; | 0 | ||||||||||||||||||
439 | else if (flags & DP_F_SPACE)
| 170-5640434 | ||||||||||||||||||
440 | signvalue = ' '; executed 170 times by 1 test: signvalue = ' '; Executed by:
| 170 | ||||||||||||||||||
441 | } executed 5641280 times by 11 tests: end of block Executed by:
| 5641280 | ||||||||||||||||||
442 | if (flags & DP_F_NUM) {
| 13-9545273 | ||||||||||||||||||
443 | if (base == 8)
| 0-13 | ||||||||||||||||||
444 | prefix = "0"; never executed: prefix = "0"; | 0 | ||||||||||||||||||
445 | if (base == 16)
| 0-13 | ||||||||||||||||||
446 | prefix = "0x"; executed 13 times by 1 test: prefix = "0x"; Executed by:
| 13 | ||||||||||||||||||
447 | } executed 13 times by 1 test: end of block Executed by:
| 13 | ||||||||||||||||||
448 | if (flags & DP_F_UP)
| 3015980-6529306 | ||||||||||||||||||
449 | caps = 1; executed 3015980 times by 1 test: caps = 1; Executed by:
| 3015980 | ||||||||||||||||||
450 | do { | - | ||||||||||||||||||
451 | convert[place++] = (caps ? "0123456789ABCDEF" : "0123456789abcdef")
| 4501188-11837074 | ||||||||||||||||||
452 | [uvalue % (unsigned)base]; | - | ||||||||||||||||||
453 | uvalue = (uvalue / (unsigned)base); | - | ||||||||||||||||||
454 | } while (uvalue && (place < (int)sizeof(convert))); executed 16338262 times by 11 tests: end of block Executed by:
| 0-16338262 | ||||||||||||||||||
455 | if (place == sizeof(convert))
| 0-9545286 | ||||||||||||||||||
456 | place--; never executed: place--; | 0 | ||||||||||||||||||
457 | convert[place] = 0; | - | ||||||||||||||||||
458 | - | |||||||||||||||||||
459 | zpadlen = max - place; | - | ||||||||||||||||||
460 | spadlen = | - | ||||||||||||||||||
461 | min - OSSL_MAX(max, place) - (signvalue ? 1 : 0) - strlen(prefix);
| 0-9545286 | ||||||||||||||||||
462 | if (zpadlen < 0)
| 0-9545286 | ||||||||||||||||||
463 | zpadlen = 0; executed 9545286 times by 11 tests: zpadlen = 0; Executed by:
| 9545286 | ||||||||||||||||||
464 | if (spadlen < 0)
| 1988699-7556587 | ||||||||||||||||||
465 | spadlen = 0; executed 1988699 times by 11 tests: spadlen = 0; Executed by:
| 1988699 | ||||||||||||||||||
466 | if (flags & DP_F_ZERO) {
| 3565471-5979815 | ||||||||||||||||||
467 | zpadlen = OSSL_MAX(zpadlen, spadlen);
| 1750806-1814665 | ||||||||||||||||||
468 | spadlen = 0; | - | ||||||||||||||||||
469 | } executed 3565471 times by 1 test: end of block Executed by:
| 3565471 | ||||||||||||||||||
470 | if (flags & DP_F_MINUS)
| 1428656-8116630 | ||||||||||||||||||
471 | spadlen = -spadlen; executed 1428656 times by 1 test: spadlen = -spadlen; Executed by:
| 1428656 | ||||||||||||||||||
472 | - | |||||||||||||||||||
473 | /* spaces */ | - | ||||||||||||||||||
474 | while (spadlen > 0) {
| 5124734-9545286 | ||||||||||||||||||
475 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen, ' '))
| 0-5124734 | ||||||||||||||||||
476 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
477 | --spadlen; | - | ||||||||||||||||||
478 | } executed 5124734 times by 1 test: end of block Executed by:
| 5124734 | ||||||||||||||||||
479 | - | |||||||||||||||||||
480 | /* sign */ | - | ||||||||||||||||||
481 | if (signvalue)
| 846-9544440 | ||||||||||||||||||
482 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue))
| 0-846 | ||||||||||||||||||
483 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
484 | - | |||||||||||||||||||
485 | /* prefix */ | - | ||||||||||||||||||
486 | while (*prefix) {
| 26-9545286 | ||||||||||||||||||
487 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen, *prefix))
| 0-26 | ||||||||||||||||||
488 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
489 | prefix++; | - | ||||||||||||||||||
490 | } executed 26 times by 1 test: end of block Executed by:
| 26 | ||||||||||||||||||
491 | - | |||||||||||||||||||
492 | /* zeros */ | - | ||||||||||||||||||
493 | if (zpadlen > 0) {
| 1814665-7730621 | ||||||||||||||||||
494 | while (zpadlen > 0) {
| 1814665-1831390 | ||||||||||||||||||
495 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen, '0'))
| 0-1831390 | ||||||||||||||||||
496 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
497 | --zpadlen; | - | ||||||||||||||||||
498 | } executed 1831390 times by 1 test: end of block Executed by:
| 1831390 | ||||||||||||||||||
499 | } executed 1814665 times by 1 test: end of block Executed by:
| 1814665 | ||||||||||||||||||
500 | /* digits */ | - | ||||||||||||||||||
501 | while (place > 0) {
| 9545286-16338262 | ||||||||||||||||||
502 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen, convert[--place]))
| 0-16338262 | ||||||||||||||||||
503 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
504 | } executed 16338262 times by 11 tests: end of block Executed by:
| 16338262 | ||||||||||||||||||
505 | - | |||||||||||||||||||
506 | /* left justified spaces */ | - | ||||||||||||||||||
507 | while (spadlen < 0) {
| 1416222-9545286 | ||||||||||||||||||
508 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen, ' '))
| 0-1416222 | ||||||||||||||||||
509 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
510 | ++spadlen; | - | ||||||||||||||||||
511 | } executed 1416222 times by 1 test: end of block Executed by:
| 1416222 | ||||||||||||||||||
512 | return 1; executed 9545286 times by 11 tests: return 1; Executed by:
| 9545286 | ||||||||||||||||||
513 | } | - | ||||||||||||||||||
514 | - | |||||||||||||||||||
515 | static LDOUBLE abs_val(LDOUBLE value) | - | ||||||||||||||||||
516 | { | - | ||||||||||||||||||
517 | LDOUBLE result = value; | - | ||||||||||||||||||
518 | if (value < 0)
| 0-357 | ||||||||||||||||||
519 | result = -value; never executed: result = -value; | 0 | ||||||||||||||||||
520 | return result; executed 357 times by 1 test: return result; Executed by:
| 357 | ||||||||||||||||||
521 | } | - | ||||||||||||||||||
522 | - | |||||||||||||||||||
523 | static LDOUBLE pow_10(int in_exp) | - | ||||||||||||||||||
524 | { | - | ||||||||||||||||||
525 | LDOUBLE result = 1; | - | ||||||||||||||||||
526 | while (in_exp) {
| 808-3008 | ||||||||||||||||||
527 | result *= 10; | - | ||||||||||||||||||
528 | in_exp--; | - | ||||||||||||||||||
529 | } executed 3008 times by 1 test: end of block Executed by:
| 3008 | ||||||||||||||||||
530 | return result; executed 808 times by 1 test: return result; Executed by:
| 808 | ||||||||||||||||||
531 | } | - | ||||||||||||||||||
532 | - | |||||||||||||||||||
533 | static long roundv(LDOUBLE value) | - | ||||||||||||||||||
534 | { | - | ||||||||||||||||||
535 | long intpart; | - | ||||||||||||||||||
536 | intpart = (long)value; | - | ||||||||||||||||||
537 | value = value - intpart; | - | ||||||||||||||||||
538 | if (value >= 0.5)
| 284-428 | ||||||||||||||||||
539 | intpart++; executed 284 times by 1 test: intpart++; Executed by:
| 284 | ||||||||||||||||||
540 | return intpart; executed 712 times by 1 test: return intpart; Executed by:
| 712 | ||||||||||||||||||
541 | } | - | ||||||||||||||||||
542 | - | |||||||||||||||||||
543 | static int | - | ||||||||||||||||||
544 | fmtfp(char **sbuffer, | - | ||||||||||||||||||
545 | char **buffer, | - | ||||||||||||||||||
546 | size_t *currlen, | - | ||||||||||||||||||
547 | size_t *maxlen, LDOUBLE fvalue, int min, int max, int flags, int style) | - | ||||||||||||||||||
548 | { | - | ||||||||||||||||||
549 | int signvalue = 0; | - | ||||||||||||||||||
550 | LDOUBLE ufvalue; | - | ||||||||||||||||||
551 | LDOUBLE tmpvalue; | - | ||||||||||||||||||
552 | char iconvert[20]; | - | ||||||||||||||||||
553 | char fconvert[20]; | - | ||||||||||||||||||
554 | char econvert[20]; | - | ||||||||||||||||||
555 | int iplace = 0; | - | ||||||||||||||||||
556 | int fplace = 0; | - | ||||||||||||||||||
557 | int eplace = 0; | - | ||||||||||||||||||
558 | int padlen = 0; | - | ||||||||||||||||||
559 | int zpadlen = 0; | - | ||||||||||||||||||
560 | long exp = 0; | - | ||||||||||||||||||
561 | unsigned long intpart; | - | ||||||||||||||||||
562 | unsigned long fracpart; | - | ||||||||||||||||||
563 | unsigned long max10; | - | ||||||||||||||||||
564 | int realstyle; | - | ||||||||||||||||||
565 | - | |||||||||||||||||||
566 | if (max < 0)
| 51-306 | ||||||||||||||||||
567 | max = 6; executed 51 times by 1 test: max = 6; Executed by:
| 51 | ||||||||||||||||||
568 | - | |||||||||||||||||||
569 | if (fvalue < 0)
| 0-357 | ||||||||||||||||||
570 | signvalue = '-'; never executed: signvalue = '-'; | 0 | ||||||||||||||||||
571 | else if (flags & DP_F_PLUS)
| 0-357 | ||||||||||||||||||
572 | signvalue = '+'; never executed: signvalue = '+'; | 0 | ||||||||||||||||||
573 | else if (flags & DP_F_SPACE)
| 0-357 | ||||||||||||||||||
574 | signvalue = ' '; never executed: signvalue = ' '; | 0 | ||||||||||||||||||
575 | - | |||||||||||||||||||
576 | /* | - | ||||||||||||||||||
577 | * G_FORMAT sometimes prints like E_FORMAT and sometimes like F_FORMAT | - | ||||||||||||||||||
578 | * depending on the number to be printed. Work out which one it is and use | - | ||||||||||||||||||
579 | * that from here on. | - | ||||||||||||||||||
580 | */ | - | ||||||||||||||||||
581 | if (style == G_FORMAT) {
| 140-217 | ||||||||||||||||||
582 | if (fvalue == 0.0) {
| 14-126 | ||||||||||||||||||
583 | realstyle = F_FORMAT; | - | ||||||||||||||||||
584 | } else if (fvalue < 0.0001) { executed 14 times by 1 test: end of block Executed by:
| 14-112 | ||||||||||||||||||
585 | realstyle = E_FORMAT; | - | ||||||||||||||||||
586 | } else if ((max == 0 && fvalue >= 10) executed 14 times by 1 test: end of block Executed by:
| 8-96 | ||||||||||||||||||
587 | || (max > 0 && fvalue >= pow_10(max))) {
| 6-96 | ||||||||||||||||||
588 | realstyle = E_FORMAT; | - | ||||||||||||||||||
589 | } else { executed 14 times by 1 test: end of block Executed by:
| 14 | ||||||||||||||||||
590 | realstyle = F_FORMAT; | - | ||||||||||||||||||
591 | } executed 98 times by 1 test: end of block Executed by:
| 98 | ||||||||||||||||||
592 | } else { | - | ||||||||||||||||||
593 | realstyle = style; | - | ||||||||||||||||||
594 | } executed 217 times by 1 test: end of block Executed by:
| 217 | ||||||||||||||||||
595 | - | |||||||||||||||||||
596 | if (style != F_FORMAT) {
| 77-280 | ||||||||||||||||||
597 | tmpvalue = fvalue; | - | ||||||||||||||||||
598 | /* Calculate the exponent */ | - | ||||||||||||||||||
599 | if (fvalue != 0.0) {
| 28-252 | ||||||||||||||||||
600 | while (tmpvalue < 1) {
| 252-308 | ||||||||||||||||||
601 | tmpvalue *= 10; | - | ||||||||||||||||||
602 | exp--; | - | ||||||||||||||||||
603 | } executed 308 times by 1 test: end of block Executed by:
| 308 | ||||||||||||||||||
604 | while (tmpvalue > 10) {
| 252-280 | ||||||||||||||||||
605 | tmpvalue /= 10; | - | ||||||||||||||||||
606 | exp++; | - | ||||||||||||||||||
607 | } executed 280 times by 1 test: end of block Executed by:
| 280 | ||||||||||||||||||
608 | } executed 252 times by 1 test: end of block Executed by:
| 252 | ||||||||||||||||||
609 | if (style == G_FORMAT) {
| 140 | ||||||||||||||||||
610 | /* | - | ||||||||||||||||||
611 | * In G_FORMAT the "precision" represents significant digits. We | - | ||||||||||||||||||
612 | * always have at least 1 significant digit. | - | ||||||||||||||||||
613 | */ | - | ||||||||||||||||||
614 | if (max == 0)
| 20-120 | ||||||||||||||||||
615 | max = 1; executed 20 times by 1 test: max = 1; Executed by:
| 20 | ||||||||||||||||||
616 | /* Now convert significant digits to decimal places */ | - | ||||||||||||||||||
617 | if (realstyle == F_FORMAT) {
| 28-112 | ||||||||||||||||||
618 | max -= (exp + 1); | - | ||||||||||||||||||
619 | if (max < 0) {
| 0-112 | ||||||||||||||||||
620 | /* | - | ||||||||||||||||||
621 | * Should not happen. If we're in F_FORMAT then exp < max? | - | ||||||||||||||||||
622 | */ | - | ||||||||||||||||||
623 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
624 | } | - | ||||||||||||||||||
625 | } else { executed 112 times by 1 test: end of block Executed by:
| 112 | ||||||||||||||||||
626 | /* | - | ||||||||||||||||||
627 | * In E_FORMAT there is always one significant digit in front | - | ||||||||||||||||||
628 | * of the decimal point, so: | - | ||||||||||||||||||
629 | * significant digits == 1 + decimal places | - | ||||||||||||||||||
630 | */ | - | ||||||||||||||||||
631 | max--; | - | ||||||||||||||||||
632 | } executed 28 times by 1 test: end of block Executed by:
| 28 | ||||||||||||||||||
633 | } | - | ||||||||||||||||||
634 | if (realstyle == E_FORMAT)
| 112-168 | ||||||||||||||||||
635 | fvalue = tmpvalue; executed 168 times by 1 test: fvalue = tmpvalue; Executed by:
| 168 | ||||||||||||||||||
636 | } executed 280 times by 1 test: end of block Executed by:
| 280 | ||||||||||||||||||
637 | ufvalue = abs_val(fvalue); | - | ||||||||||||||||||
638 | if (ufvalue > ULONG_MAX) {
| 1-356 | ||||||||||||||||||
639 | /* Number too big */ | - | ||||||||||||||||||
640 | return 0; executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||||||||
641 | } | - | ||||||||||||||||||
642 | intpart = (unsigned long)ufvalue; | - | ||||||||||||||||||
643 | - | |||||||||||||||||||
644 | /* | - | ||||||||||||||||||
645 | * sorry, we only support 9 digits past the decimal because of our | - | ||||||||||||||||||
646 | * conversion method | - | ||||||||||||||||||
647 | */ | - | ||||||||||||||||||
648 | if (max > 9)
| 0-356 | ||||||||||||||||||
649 | max = 9; never executed: max = 9; | 0 | ||||||||||||||||||
650 | - | |||||||||||||||||||
651 | /* | - | ||||||||||||||||||
652 | * we "cheat" by converting the fractional part to integer by multiplying | - | ||||||||||||||||||
653 | * by a factor of 10 | - | ||||||||||||||||||
654 | */ | - | ||||||||||||||||||
655 | max10 = roundv(pow_10(max)); | - | ||||||||||||||||||
656 | fracpart = roundv(pow_10(max) * (ufvalue - intpart)); | - | ||||||||||||||||||
657 | - | |||||||||||||||||||
658 | if (fracpart >= max10) {
| 47-309 | ||||||||||||||||||
659 | intpart++; | - | ||||||||||||||||||
660 | fracpart -= max10; | - | ||||||||||||||||||
661 | } executed 47 times by 1 test: end of block Executed by:
| 47 | ||||||||||||||||||
662 | - | |||||||||||||||||||
663 | /* convert integer part */ | - | ||||||||||||||||||
664 | do { | - | ||||||||||||||||||
665 | iconvert[iplace++] = "0123456789"[intpart % 10]; | - | ||||||||||||||||||
666 | intpart = (intpart / 10); | - | ||||||||||||||||||
667 | } while (intpart && (iplace < (int)sizeof(iconvert))); executed 522 times by 1 test: end of block Executed by:
| 0-522 | ||||||||||||||||||
668 | if (iplace == sizeof(iconvert))
| 0-356 | ||||||||||||||||||
669 | iplace--; never executed: iplace--; | 0 | ||||||||||||||||||
670 | iconvert[iplace] = 0; | - | ||||||||||||||||||
671 | - | |||||||||||||||||||
672 | /* convert fractional part */ | - | ||||||||||||||||||
673 | while (fplace < max) {
| 344-1280 | ||||||||||||||||||
674 | if (style == G_FORMAT && fplace == 0 && (fracpart % 10) == 0) {
| 76-852 | ||||||||||||||||||
675 | /* We strip trailing zeros in G_FORMAT */ | - | ||||||||||||||||||
676 | max--; | - | ||||||||||||||||||
677 | fracpart = fracpart / 10; | - | ||||||||||||||||||
678 | if (fplace < max)
| 12-64 | ||||||||||||||||||
679 | continue; executed 64 times by 1 test: continue; Executed by:
| 64 | ||||||||||||||||||
680 | break; executed 12 times by 1 test: break; Executed by:
| 12 | ||||||||||||||||||
681 | } | - | ||||||||||||||||||
682 | fconvert[fplace++] = "0123456789"[fracpart % 10]; | - | ||||||||||||||||||
683 | fracpart = (fracpart / 10); | - | ||||||||||||||||||
684 | } executed 1204 times by 1 test: end of block Executed by:
| 1204 | ||||||||||||||||||
685 | - | |||||||||||||||||||
686 | if (fplace == sizeof(fconvert))
| 0-356 | ||||||||||||||||||
687 | fplace--; never executed: fplace--; | 0 | ||||||||||||||||||
688 | fconvert[fplace] = 0; | - | ||||||||||||||||||
689 | - | |||||||||||||||||||
690 | /* convert exponent part */ | - | ||||||||||||||||||
691 | if (realstyle == E_FORMAT) {
| 168-188 | ||||||||||||||||||
692 | int tmpexp; | - | ||||||||||||||||||
693 | if (exp < 0)
| 70-98 | ||||||||||||||||||
694 | tmpexp = -exp; executed 70 times by 1 test: tmpexp = -exp; Executed by:
| 70 | ||||||||||||||||||
695 | else | - | ||||||||||||||||||
696 | tmpexp = exp; executed 98 times by 1 test: tmpexp = exp; Executed by:
| 98 | ||||||||||||||||||
697 | - | |||||||||||||||||||
698 | do { | - | ||||||||||||||||||
699 | econvert[eplace++] = "0123456789"[tmpexp % 10]; | - | ||||||||||||||||||
700 | tmpexp = (tmpexp / 10); | - | ||||||||||||||||||
701 | } while (tmpexp > 0 && eplace < (int)sizeof(econvert)); executed 168 times by 1 test: end of block Executed by:
| 0-168 | ||||||||||||||||||
702 | /* Exponent is huge!! Too big to print */ | - | ||||||||||||||||||
703 | if (tmpexp > 0)
| 0-168 | ||||||||||||||||||
704 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
705 | /* Add a leading 0 for single digit exponents */ | - | ||||||||||||||||||
706 | if (eplace == 1)
| 0-168 | ||||||||||||||||||
707 | econvert[eplace++] = '0'; executed 168 times by 1 test: econvert[eplace++] = '0'; Executed by:
| 168 | ||||||||||||||||||
708 | } executed 168 times by 1 test: end of block Executed by:
| 168 | ||||||||||||||||||
709 | - | |||||||||||||||||||
710 | /* | - | ||||||||||||||||||
711 | * -1 for decimal point (if we have one, i.e. max > 0), | - | ||||||||||||||||||
712 | * another -1 if we are printing a sign | - | ||||||||||||||||||
713 | */ | - | ||||||||||||||||||
714 | padlen = min - iplace - max - (max > 0 ? 1 : 0) - ((signvalue) ? 1 : 0);
| 0-356 | ||||||||||||||||||
715 | /* Take some off for exponent prefix "+e" and exponent */ | - | ||||||||||||||||||
716 | if (realstyle == E_FORMAT)
| 168-188 | ||||||||||||||||||
717 | padlen -= 2 + eplace; executed 168 times by 1 test: padlen -= 2 + eplace; Executed by:
| 168 | ||||||||||||||||||
718 | zpadlen = max - fplace; | - | ||||||||||||||||||
719 | if (zpadlen < 0)
| 0-356 | ||||||||||||||||||
720 | zpadlen = 0; never executed: zpadlen = 0; | 0 | ||||||||||||||||||
721 | if (padlen < 0)
| 128-228 | ||||||||||||||||||
722 | padlen = 0; executed 228 times by 1 test: padlen = 0; Executed by:
| 228 | ||||||||||||||||||
723 | if (flags & DP_F_MINUS)
| 0-356 | ||||||||||||||||||
724 | padlen = -padlen; never executed: padlen = -padlen; | 0 | ||||||||||||||||||
725 | - | |||||||||||||||||||
726 | if ((flags & DP_F_ZERO) && (padlen > 0)) {
| 21-306 | ||||||||||||||||||
727 | if (signvalue) {
| 0-21 | ||||||||||||||||||
728 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue))
| 0 | ||||||||||||||||||
729 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
730 | --padlen; | - | ||||||||||||||||||
731 | signvalue = 0; | - | ||||||||||||||||||
732 | } never executed: end of block | 0 | ||||||||||||||||||
733 | while (padlen > 0) {
| 21-65 | ||||||||||||||||||
734 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen, '0'))
| 0-65 | ||||||||||||||||||
735 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
736 | --padlen; | - | ||||||||||||||||||
737 | } executed 65 times by 1 test: end of block Executed by:
| 65 | ||||||||||||||||||
738 | } executed 21 times by 1 test: end of block Executed by:
| 21 | ||||||||||||||||||
739 | while (padlen > 0) {
| 356-406 | ||||||||||||||||||
740 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen, ' '))
| 0-406 | ||||||||||||||||||
741 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
742 | --padlen; | - | ||||||||||||||||||
743 | } executed 406 times by 1 test: end of block Executed by:
| 406 | ||||||||||||||||||
744 | if (signvalue && !doapr_outch(sbuffer, buffer, currlen, maxlen, signvalue))
| 0-356 | ||||||||||||||||||
745 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
746 | - | |||||||||||||||||||
747 | while (iplace > 0) {
| 356-522 | ||||||||||||||||||
748 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen, iconvert[--iplace]))
| 0-522 | ||||||||||||||||||
749 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
750 | } executed 522 times by 1 test: end of block Executed by:
| 522 | ||||||||||||||||||
751 | - | |||||||||||||||||||
752 | /* | - | ||||||||||||||||||
753 | * Decimal point. This should probably use locale to find the correct | - | ||||||||||||||||||
754 | * char to print out. | - | ||||||||||||||||||
755 | */ | - | ||||||||||||||||||
756 | if (max > 0 || (flags & DP_F_NUM)) {
| 0-290 | ||||||||||||||||||
757 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen, '.'))
| 0-290 | ||||||||||||||||||
758 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
759 | - | |||||||||||||||||||
760 | while (fplace > 0) {
| 290-1204 | ||||||||||||||||||
761 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen,
| 0-1204 | ||||||||||||||||||
762 | fconvert[--fplace]))
| 0-1204 | ||||||||||||||||||
763 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
764 | } executed 1204 times by 1 test: end of block Executed by:
| 1204 | ||||||||||||||||||
765 | } executed 290 times by 1 test: end of block Executed by:
| 290 | ||||||||||||||||||
766 | while (zpadlen > 0) {
| 0-356 | ||||||||||||||||||
767 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen, '0'))
| 0 | ||||||||||||||||||
768 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
769 | --zpadlen; | - | ||||||||||||||||||
770 | } never executed: end of block | 0 | ||||||||||||||||||
771 | if (realstyle == E_FORMAT) {
| 168-188 | ||||||||||||||||||
772 | char ech; | - | ||||||||||||||||||
773 | - | |||||||||||||||||||
774 | if ((flags & DP_F_UP) == 0)
| 84 | ||||||||||||||||||
775 | ech = 'e'; executed 84 times by 1 test: ech = 'e'; Executed by:
| 84 | ||||||||||||||||||
776 | else | - | ||||||||||||||||||
777 | ech = 'E'; executed 84 times by 1 test: ech = 'E'; Executed by:
| 84 | ||||||||||||||||||
778 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen, ech))
| 0-168 | ||||||||||||||||||
779 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
780 | if (exp < 0) {
| 70-98 | ||||||||||||||||||
781 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen, '-'))
| 0-70 | ||||||||||||||||||
782 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
783 | } else { executed 70 times by 1 test: end of block Executed by:
| 70 | ||||||||||||||||||
784 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen, '+'))
| 0-98 | ||||||||||||||||||
785 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
786 | } executed 98 times by 1 test: end of block Executed by:
| 98 | ||||||||||||||||||
787 | while (eplace > 0) {
| 168-336 | ||||||||||||||||||
788 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen,
| 0-336 | ||||||||||||||||||
789 | econvert[--eplace]))
| 0-336 | ||||||||||||||||||
790 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
791 | } executed 336 times by 1 test: end of block Executed by:
| 336 | ||||||||||||||||||
792 | } executed 168 times by 1 test: end of block Executed by:
| 168 | ||||||||||||||||||
793 | - | |||||||||||||||||||
794 | while (padlen < 0) {
| 0-356 | ||||||||||||||||||
795 | if (!doapr_outch(sbuffer, buffer, currlen, maxlen, ' '))
| 0 | ||||||||||||||||||
796 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
797 | ++padlen; | - | ||||||||||||||||||
798 | } never executed: end of block | 0 | ||||||||||||||||||
799 | return 1; executed 356 times by 1 test: return 1; Executed by:
| 356 | ||||||||||||||||||
800 | } | - | ||||||||||||||||||
801 | - | |||||||||||||||||||
802 | #define BUFFER_INC 1024 | - | ||||||||||||||||||
803 | - | |||||||||||||||||||
804 | static int | - | ||||||||||||||||||
805 | doapr_outch(char **sbuffer, | - | ||||||||||||||||||
806 | char **buffer, size_t *currlen, size_t *maxlen, int c) | - | ||||||||||||||||||
807 | { | - | ||||||||||||||||||
808 | /* If we haven't at least one buffer, someone has done a big booboo */ | - | ||||||||||||||||||
809 | if (!ossl_assert(*sbuffer != NULL || buffer != NULL))
| 0-88059099 | ||||||||||||||||||
810 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
811 | - | |||||||||||||||||||
812 | /* |currlen| must always be <= |*maxlen| */ | - | ||||||||||||||||||
813 | if (!ossl_assert(*currlen <= *maxlen))
| 0-88059099 | ||||||||||||||||||
814 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
815 | - | |||||||||||||||||||
816 | if (buffer && *currlen == *maxlen) {
| 284-83340045 | ||||||||||||||||||
817 | if (*maxlen > INT_MAX - BUFFER_INC)
| 0-284 | ||||||||||||||||||
818 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
819 | - | |||||||||||||||||||
820 | *maxlen += BUFFER_INC; | - | ||||||||||||||||||
821 | if (*buffer == NULL) {
| 88-196 | ||||||||||||||||||
822 | if ((*buffer = OPENSSL_malloc(*maxlen)) == NULL) {
| 0-88 | ||||||||||||||||||
823 | BIOerr(BIO_F_DOAPR_OUTCH, ERR_R_MALLOC_FAILURE); | - | ||||||||||||||||||
824 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
825 | } | - | ||||||||||||||||||
826 | if (*currlen > 0) {
| 0-88 | ||||||||||||||||||
827 | if (!ossl_assert(*sbuffer != NULL))
| 0-88 | ||||||||||||||||||
828 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
829 | memcpy(*buffer, *sbuffer, *currlen); | - | ||||||||||||||||||
830 | } executed 88 times by 1 test: end of block Executed by:
| 88 | ||||||||||||||||||
831 | *sbuffer = NULL; | - | ||||||||||||||||||
832 | } else { executed 88 times by 1 test: end of block Executed by:
| 88 | ||||||||||||||||||
833 | char *tmpbuf; | - | ||||||||||||||||||
834 | tmpbuf = OPENSSL_realloc(*buffer, *maxlen); | - | ||||||||||||||||||
835 | if (tmpbuf == NULL)
| 0-196 | ||||||||||||||||||
836 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
837 | *buffer = tmpbuf; | - | ||||||||||||||||||
838 | } executed 196 times by 1 test: end of block Executed by:
| 196 | ||||||||||||||||||
839 | } | - | ||||||||||||||||||
840 | - | |||||||||||||||||||
841 | if (*currlen < *maxlen) {
| 0-88059099 | ||||||||||||||||||
842 | if (*sbuffer)
| 211574-87847525 | ||||||||||||||||||
843 | (*sbuffer)[(*currlen)++] = (char)c; executed 87847525 times by 12 tests: (*sbuffer)[(*currlen)++] = (char)c; Executed by:
| 87847525 | ||||||||||||||||||
844 | else | - | ||||||||||||||||||
845 | (*buffer)[(*currlen)++] = (char)c; executed 211574 times by 1 test: (*buffer)[(*currlen)++] = (char)c; Executed by:
| 211574 | ||||||||||||||||||
846 | } | - | ||||||||||||||||||
847 | - | |||||||||||||||||||
848 | return 1; executed 88059099 times by 12 tests: return 1; Executed by:
| 88059099 | ||||||||||||||||||
849 | } | - | ||||||||||||||||||
850 | - | |||||||||||||||||||
851 | /***************************************************************************/ | - | ||||||||||||||||||
852 | - | |||||||||||||||||||
853 | int BIO_printf(BIO *bio, const char *format, ...) | - | ||||||||||||||||||
854 | { | - | ||||||||||||||||||
855 | va_list args; | - | ||||||||||||||||||
856 | int ret; | - | ||||||||||||||||||
857 | - | |||||||||||||||||||
858 | va_start(args, format); | - | ||||||||||||||||||
859 | - | |||||||||||||||||||
860 | ret = BIO_vprintf(bio, format, args); | - | ||||||||||||||||||
861 | - | |||||||||||||||||||
862 | va_end(args); | - | ||||||||||||||||||
863 | return ret; executed 8142828 times by 1 test: return ret; Executed by:
| 8142828 | ||||||||||||||||||
864 | } | - | ||||||||||||||||||
865 | - | |||||||||||||||||||
866 | int BIO_vprintf(BIO *bio, const char *format, va_list args) | - | ||||||||||||||||||
867 | { | - | ||||||||||||||||||
868 | int ret; | - | ||||||||||||||||||
869 | size_t retlen; | - | ||||||||||||||||||
870 | char hugebuf[1024 * 2]; /* Was previously 10k, which is unreasonable | - | ||||||||||||||||||
871 | * in small-stack environments, like threads | - | ||||||||||||||||||
872 | * or DOS programs. */ | - | ||||||||||||||||||
873 | char *hugebufp = hugebuf; | - | ||||||||||||||||||
874 | size_t hugebufsize = sizeof(hugebuf); | - | ||||||||||||||||||
875 | char *dynbuf = NULL; | - | ||||||||||||||||||
876 | int ignored; | - | ||||||||||||||||||
877 | - | |||||||||||||||||||
878 | dynbuf = NULL; | - | ||||||||||||||||||
879 | if (!_dopr(&hugebufp, &dynbuf, &hugebufsize, &retlen, &ignored, format,
| 0-8182536 | ||||||||||||||||||
880 | args)) {
| 0-8182536 | ||||||||||||||||||
881 | OPENSSL_free(dynbuf); | - | ||||||||||||||||||
882 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
883 | } | - | ||||||||||||||||||
884 | if (dynbuf) {
| 88-8182448 | ||||||||||||||||||
885 | ret = BIO_write(bio, dynbuf, (int)retlen); | - | ||||||||||||||||||
886 | OPENSSL_free(dynbuf); | - | ||||||||||||||||||
887 | } else { executed 88 times by 1 test: end of block Executed by:
| 88 | ||||||||||||||||||
888 | ret = BIO_write(bio, hugebuf, (int)retlen); | - | ||||||||||||||||||
889 | } executed 8182448 times by 12 tests: end of block Executed by:
| 8182448 | ||||||||||||||||||
890 | return ret; executed 8182536 times by 12 tests: return ret; Executed by:
| 8182536 | ||||||||||||||||||
891 | } | - | ||||||||||||||||||
892 | - | |||||||||||||||||||
893 | /* | - | ||||||||||||||||||
894 | * As snprintf is not available everywhere, we provide our own | - | ||||||||||||||||||
895 | * implementation. This function has nothing to do with BIOs, but it's | - | ||||||||||||||||||
896 | * closely related to BIO_printf, and we need *some* name prefix ... (XXX the | - | ||||||||||||||||||
897 | * function should be renamed, but to what?) | - | ||||||||||||||||||
898 | */ | - | ||||||||||||||||||
899 | int BIO_snprintf(char *buf, size_t n, const char *format, ...) | - | ||||||||||||||||||
900 | { | - | ||||||||||||||||||
901 | va_list args; | - | ||||||||||||||||||
902 | int ret; | - | ||||||||||||||||||
903 | - | |||||||||||||||||||
904 | va_start(args, format); | - | ||||||||||||||||||
905 | - | |||||||||||||||||||
906 | ret = BIO_vsnprintf(buf, n, format, args); | - | ||||||||||||||||||
907 | - | |||||||||||||||||||
908 | va_end(args); | - | ||||||||||||||||||
909 | return ret; executed 693767 times by 1 test: return ret; Executed by:
| 693767 | ||||||||||||||||||
910 | } | - | ||||||||||||||||||
911 | - | |||||||||||||||||||
912 | int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args) | - | ||||||||||||||||||
913 | { | - | ||||||||||||||||||
914 | size_t retlen; | - | ||||||||||||||||||
915 | int truncated; | - | ||||||||||||||||||
916 | - | |||||||||||||||||||
917 | if (!_dopr(&buf, NULL, &n, &retlen, &truncated, format, args))
| 1-693766 | ||||||||||||||||||
918 | return -1; executed 1 time by 1 test: return -1; Executed by:
| 1 | ||||||||||||||||||
919 | - | |||||||||||||||||||
920 | if (truncated)
| 0-693766 | ||||||||||||||||||
921 | /* | - | ||||||||||||||||||
922 | * In case of truncation, return -1 like traditional snprintf. | - | ||||||||||||||||||
923 | * (Current drafts for ISO/IEC 9899 say snprintf should return the | - | ||||||||||||||||||
924 | * number of characters that would have been written, had the buffer | - | ||||||||||||||||||
925 | * been large enough.) | - | ||||||||||||||||||
926 | */ | - | ||||||||||||||||||
927 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
928 | else | - | ||||||||||||||||||
929 | return (retlen <= INT_MAX) ? (int)retlen : -1; executed 693766 times by 1 test: return (retlen <= 0x7fffffff) ? (int)retlen : -1; Executed by:
| 0-693766 | ||||||||||||||||||
930 | } | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |