blob: 6ea52011616639cca3c41b888ac63ecc0381f718 [file] [log] [blame]
Lev Walkin41ba1f22004-09-14 12:46:35 +00001/*-
Lev Walkina5972be2017-09-29 23:15:58 -07002 * Copyright (c) 2004-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
Lev Walkin41ba1f22004-09-14 12:46:35 +00003 * Redistribution and modifications are permitted subject to BSD license.
4 */
Lev Walkine9360e62013-03-28 00:21:57 -07005#define _ISOC99_SOURCE /* For ilogb() and quiet NAN */
Vasil Velichkovadf65942016-08-01 16:52:02 +03006#ifndef _BSD_SOURCE
Lev Walkin1aea6982004-10-26 09:35:25 +00007#define _BSD_SOURCE /* To reintroduce finite(3) */
Vasil Velichkovadf65942016-08-01 16:52:02 +03008#endif
Lev Walkin73823e12013-03-28 00:24:48 -07009#if defined(__alpha)
Lev Walkin1aea6982004-10-26 09:35:25 +000010#include <sys/resource.h> /* For INFINITY */
Lev Walkin33700162004-10-26 09:03:31 +000011#endif
Lev Walkina9cc46e2004-09-22 16:06:28 +000012#include <asn_internal.h>
Lev Walkin41ba1f22004-09-14 12:46:35 +000013#include <stdlib.h> /* for strtod(3) */
14#include <math.h>
15#include <errno.h>
Lev Walkin33700162004-10-26 09:03:31 +000016#include <REAL.h>
Lev Walkin725883b2006-10-09 12:07:58 +000017#include <OCTET_STRING.h>
Lev Walkin41ba1f22004-09-14 12:46:35 +000018
19#undef INT_MAX
20#define INT_MAX ((int)(((unsigned int)-1) >> 1))
21
Lev Walkin1aea6982004-10-26 09:35:25 +000022#if !(defined(NAN) || defined(INFINITY))
Lev Walkin3f995632017-09-26 18:27:32 -070023static volatile double real_zero CC_NOTUSED = 0.0;
Lev Walkin1aea6982004-10-26 09:35:25 +000024#endif
Lev Walkinae1bce92004-09-27 22:18:34 +000025#ifndef NAN
Lev Walkinc51e7d62004-09-27 22:16:18 +000026#define NAN (real_zero/real_zero)
Lev Walkin40319a12004-09-14 13:40:42 +000027#endif
Lev Walkin1aea6982004-10-26 09:35:25 +000028#ifndef INFINITY
29#define INFINITY (1.0/real_zero)
30#endif
Lev Walkin40319a12004-09-14 13:40:42 +000031
Lev Walkineff98a52017-09-13 22:24:35 +000032#if defined(__clang__)
33/*
34 * isnan() is defined using generic selections and won't compile in
35 * strict C89 mode because of too fancy system's standard library.
36 * However, prior to C11 the math had a perfectly working isnan()
37 * in the math library.
38 * Disable generic selection warning so we can test C89 mode with newer libc.
39 */
40#pragma clang diagnostic push
41#pragma clang diagnostic ignored "-Wc11-extensions"
42static int asn_isnan(double d) {
43 return isnan(d);
44}
45static int asn_isfinite(double d) {
Lev Walkindaeb2162014-01-13 23:08:35 -080046#ifdef isfinite
Lev Walkineff98a52017-09-13 22:24:35 +000047 return isfinite(d); /* ISO C99 */
Lev Walkindaeb2162014-01-13 23:08:35 -080048#else
Lev Walkineff98a52017-09-13 22:24:35 +000049 return finite(d); /* Deprecated on Mac OS X 10.9 */
Lev Walkindaeb2162014-01-13 23:08:35 -080050#endif
Lev Walkineff98a52017-09-13 22:24:35 +000051}
52#pragma clang diagnostic pop
53#else /* !clang */
54#define asn_isnan(v) isnan(v)
55#ifdef isfinite
56#define asn_isfinite(d) isfinite(d) /* ISO C99 */
57#else
58#define asn_isfinite(d) finite(d) /* Deprecated on Mac OS X 10.9 */
59#endif
60#endif /* clang */
61
Lev Walkindaeb2162014-01-13 23:08:35 -080062
Lev Walkin41ba1f22004-09-14 12:46:35 +000063/*
64 * REAL basic type description.
65 */
Wim Lewis18c2ec92014-07-29 11:30:10 -070066static const ber_tlv_tag_t asn_DEF_REAL_tags[] = {
Lev Walkin41ba1f22004-09-14 12:46:35 +000067 (ASN_TAG_CLASS_UNIVERSAL | (9 << 2))
68};
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +080069asn_TYPE_operation_t asn_OP_REAL = {
70 ASN__PRIMITIVE_TYPE_free,
71 REAL_print,
72 REAL_compare,
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +080073 ber_decode_primitive,
74 der_encode_primitive,
75 REAL_decode_xer,
76 REAL_encode_xer,
Lev Walkincc159472017-07-06 08:26:36 -070077#ifdef ASN_DISABLE_OER_SUPPORT
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +080078 0,
79 0,
Lev Walkincc159472017-07-06 08:26:36 -070080#else
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +080081 0,
82 0,
Lev Walkincc159472017-07-06 08:26:36 -070083#endif /* ASN_DISABLE_OER_SUPPORT */
Lev Walkinb33425f2017-07-14 14:59:52 +040084#ifdef ASN_DISABLE_PER_SUPPORT
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +080085 0,
86 0,
Lev Walkinb33425f2017-07-14 14:59:52 +040087#else
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +080088 REAL_decode_uper,
89 REAL_encode_uper,
Lev Walkinb33425f2017-07-14 14:59:52 +040090#endif /* ASN_DISABLE_PER_SUPPORT */
Lev Walkina5972be2017-09-29 23:15:58 -070091 REAL_random_fill,
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +080092 0 /* Use generic outmost tag fetcher */
93};
94asn_TYPE_descriptor_t asn_DEF_REAL = {
95 "REAL",
96 "REAL",
97 &asn_OP_REAL,
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +080098 asn_DEF_REAL_tags,
99 sizeof(asn_DEF_REAL_tags) / sizeof(asn_DEF_REAL_tags[0]),
100 asn_DEF_REAL_tags, /* Same as above */
101 sizeof(asn_DEF_REAL_tags) / sizeof(asn_DEF_REAL_tags[0]),
Lev Walkina5972be2017-09-29 23:15:58 -0700102 { 0, 0, asn_generic_no_constraint },
Bi-Ruei, Chiu1f87ac02017-08-20 01:25:45 +0800103 0,
104 0, /* No members */
105 0 /* No specifics */
Lev Walkin41ba1f22004-09-14 12:46:35 +0000106};
107
Lev Walkin5f560912004-10-21 13:37:57 +0000108typedef enum specialRealValue {
109 SRV__NOT_A_NUMBER,
110 SRV__MINUS_INFINITY,
111 SRV__PLUS_INFINITY
112} specialRealValue_e;
113static struct specialRealValue_s {
114 char *string;
Lev Walkin8471cec2004-10-21 14:02:19 +0000115 size_t length;
Lev Walkin1aea6982004-10-26 09:35:25 +0000116 long dv;
Lev Walkin5f560912004-10-21 13:37:57 +0000117} specialRealValue[] = {
118#define SRV_SET(foo, val) { foo, sizeof(foo) - 1, val }
Lev Walkin1aea6982004-10-26 09:35:25 +0000119 SRV_SET("<NOT-A-NUMBER/>", 0),
120 SRV_SET("<MINUS-INFINITY/>", -1),
121 SRV_SET("<PLUS-INFINITY/>", 1),
Lev Walkin5f560912004-10-21 13:37:57 +0000122#undef SRV_SET
123};
124
Lev Walkina9cc46e2004-09-22 16:06:28 +0000125ssize_t
126REAL__dump(double d, int canonical, asn_app_consume_bytes_f *cb, void *app_key) {
Lev Walkin92b35d22004-09-27 20:52:18 +0000127 char local_buf[64];
Lev Walkina9cc46e2004-09-22 16:06:28 +0000128 char *buf = local_buf;
129 ssize_t buflen = sizeof(local_buf);
Lev Walkinab1d1e12017-10-03 18:43:12 -0700130 const char *fmt = canonical ? "%.17E" /* Precise */ : "%.15f" /* Pleasant*/;
Lev Walkina9cc46e2004-09-22 16:06:28 +0000131 ssize_t ret;
132
Lev Walkin8e8078a2004-09-26 13:10:40 +0000133 /*
134 * Check whether it is a special value.
135 */
Lev Walkinc51e7d62004-09-27 22:16:18 +0000136 /* fpclassify(3) is not portable yet */
Lev Walkineff98a52017-09-13 22:24:35 +0000137 if(asn_isnan(d)) {
Lev Walkin5f560912004-10-21 13:37:57 +0000138 buf = specialRealValue[SRV__NOT_A_NUMBER].string;
139 buflen = specialRealValue[SRV__NOT_A_NUMBER].length;
Lev Walkinc51e7d62004-09-27 22:16:18 +0000140 return (cb(buf, buflen, app_key) < 0) ? -1 : buflen;
Lev Walkineff98a52017-09-13 22:24:35 +0000141 } else if(!asn_isfinite(d)) {
Lev Walkinc51e7d62004-09-27 22:16:18 +0000142 if(copysign(1.0, d) < 0.0) {
Lev Walkin5f560912004-10-21 13:37:57 +0000143 buf = specialRealValue[SRV__MINUS_INFINITY].string;
144 buflen = specialRealValue[SRV__MINUS_INFINITY].length;
Lev Walkinc51e7d62004-09-27 22:16:18 +0000145 } else {
Lev Walkin5f560912004-10-21 13:37:57 +0000146 buf = specialRealValue[SRV__PLUS_INFINITY].string;
147 buflen = specialRealValue[SRV__PLUS_INFINITY].length;
Lev Walkinc51e7d62004-09-27 22:16:18 +0000148 }
149 return (cb(buf, buflen, app_key) < 0) ? -1 : buflen;
150 } else if(ilogb(d) <= -INT_MAX) {
151 if(copysign(1.0, d) < 0.0) {
152 buf = "-0";
153 buflen = 2;
154 } else {
155 buf = "0";
156 buflen = 1;
Lev Walkin8e8078a2004-09-26 13:10:40 +0000157 }
158 return (cb(buf, buflen, app_key) < 0) ? -1 : buflen;
159 }
160
161 /*
162 * Use the libc's double printing, hopefully they got it right.
163 */
Lev Walkina9cc46e2004-09-22 16:06:28 +0000164 do {
165 ret = snprintf(buf, buflen, fmt, d);
166 if(ret < 0) {
167 buflen <<= 1;
168 } else if(ret >= buflen) {
169 buflen = ret + 1;
170 } else {
171 buflen = ret;
172 break;
173 }
Lev Walkin419f6752006-09-13 04:02:00 +0000174 if(buf != local_buf) FREEMEM(buf);
Lev Walkin8e8078a2004-09-26 13:10:40 +0000175 buf = (char *)MALLOC(buflen);
Lev Walkina9cc46e2004-09-22 16:06:28 +0000176 if(!buf) return -1;
177 } while(1);
178
Lev Walkina9cc46e2004-09-22 16:06:28 +0000179 if(canonical) {
Lev Walkin92b35d22004-09-27 20:52:18 +0000180 /*
181 * Transform the "[-]d.dddE+-dd" output into "[-]d.dddE[-]d"
Lev Walkin5f560912004-10-21 13:37:57 +0000182 * Check that snprintf() constructed the output correctly.
Lev Walkin92b35d22004-09-27 20:52:18 +0000183 */
Lev Walkin8ca13c82016-01-24 22:40:00 -0800184 char *dot;
Lev Walkina9cc46e2004-09-22 16:06:28 +0000185 char *end = buf + buflen;
Lev Walkin92b35d22004-09-27 20:52:18 +0000186 char *last_zero;
Lev Walkin8ca13c82016-01-24 22:40:00 -0800187 char *prev_zero;
188 char *s;
189
190 enum {
191 LZSTATE_NOTHING,
192 LZSTATE_SEEN_ZERO
193 } lz_state = LZSTATE_NOTHING;
Lev Walkina9cc46e2004-09-22 16:06:28 +0000194
Lev Walkin5f560912004-10-21 13:37:57 +0000195 dot = (buf[0] == 0x2d /* '-' */) ? (buf + 2) : (buf + 1);
Lev Walkina9cc46e2004-09-22 16:06:28 +0000196 if(*dot >= 0x30) {
Lev Walkin78d917d2012-01-07 15:29:08 -0800197 if(buf != local_buf) FREEMEM(buf);
Lev Walkina9cc46e2004-09-22 16:06:28 +0000198 errno = EINVAL;
199 return -1; /* Not a dot, really */
200 }
Lev Walkin92b35d22004-09-27 20:52:18 +0000201 *dot = 0x2e; /* Replace possible comma */
Lev Walkina9cc46e2004-09-22 16:06:28 +0000202
Lev Walkin8ca13c82016-01-24 22:40:00 -0800203 for(prev_zero = last_zero = s = dot + 2; s < end; s++) {
204 switch(*s) {
205 case 0x45: /* 'E' */
206 if(lz_state == LZSTATE_SEEN_ZERO)
207 last_zero = prev_zero;
208 break;
209 case 0x30: /* '0' */
210 if(lz_state == LZSTATE_NOTHING)
211 prev_zero = s;
212 lz_state = LZSTATE_SEEN_ZERO;
213 continue;
214 default:
215 lz_state = LZSTATE_NOTHING;
216 continue;
217 }
218 break;
219 }
220
221 if(s == end) {
Lev Walkin78d917d2012-01-07 15:29:08 -0800222 if(buf != local_buf) FREEMEM(buf);
Lev Walkina9cc46e2004-09-22 16:06:28 +0000223 errno = EINVAL;
224 return -1; /* No promised E */
225 }
Lev Walkin8ca13c82016-01-24 22:40:00 -0800226
227 assert(*s == 0x45);
228 {
229 char *E = s;
230 char *expptr = ++E;
231 char *s = expptr;
232 int sign;
233
234 if(*expptr == 0x2b /* '+' */) {
235 /* Skip the "+" */
236 buflen -= 1;
237 sign = 0;
238 } else {
239 sign = 1;
240 s++;
241 }
242 expptr++;
243 if(expptr > end) {
244 if(buf != local_buf) FREEMEM(buf);
245 errno = EINVAL;
246 return -1;
247 }
248 if(*expptr == 0x30) {
249 buflen--;
250 expptr++;
251 }
252 if(*last_zero == 0x30) {
253 *last_zero = 0x45; /* E */
254 buflen -= s - (last_zero + 1);
255 s = last_zero + 1;
256 if(sign) {
257 *s++ = 0x2d /* '-' */;
258 buflen++;
259 }
260 }
261 for(; expptr <= end; s++, expptr++)
262 *s = *expptr;
263 }
Lev Walkin92b35d22004-09-27 20:52:18 +0000264 } else {
265 /*
266 * Remove trailing zeros.
267 */
268 char *end = buf + buflen;
269 char *last_zero = end;
Lev Walkinf0b808d2005-04-25 21:08:25 +0000270 int stoplooking = 0;
Lev Walkin92b35d22004-09-27 20:52:18 +0000271 char *z;
272 for(z = end - 1; z > buf; z--) {
273 switch(*z) {
Lev Walkinf0b808d2005-04-25 21:08:25 +0000274 case 0x30:
275 if(!stoplooking)
276 last_zero = z;
277 continue;
Lev Walkin92b35d22004-09-27 20:52:18 +0000278 case 0x31: case 0x32: case 0x33: case 0x34:
279 case 0x35: case 0x36: case 0x37: case 0x38: case 0x39:
Lev Walkinf0b808d2005-04-25 21:08:25 +0000280 stoplooking = 1;
Lev Walkin92b35d22004-09-27 20:52:18 +0000281 continue;
282 default: /* Catch dot and other separators */
Lev Walkinf0b808d2005-04-25 21:08:25 +0000283 /*
284 * Replace possible comma (which may even
285 * be not a comma at all: locale-defined).
286 */
287 *z = 0x2e;
Lev Walkin92b35d22004-09-27 20:52:18 +0000288 if(last_zero == z + 1) { /* leave x.0 */
289 last_zero++;
290 }
291 buflen = last_zero - buf;
292 *last_zero = '\0';
293 break;
294 }
295 break;
296 }
Lev Walkina9cc46e2004-09-22 16:06:28 +0000297 }
298
299 ret = cb(buf, buflen, app_key);
Lev Walkin419f6752006-09-13 04:02:00 +0000300 if(buf != local_buf) FREEMEM(buf);
Lev Walkina9cc46e2004-09-22 16:06:28 +0000301 return (ret < 0) ? -1 : buflen;
302}
303
Lev Walkin41ba1f22004-09-14 12:46:35 +0000304int
Lev Walkin5e033762004-09-29 13:26:15 +0000305REAL_print(asn_TYPE_descriptor_t *td, const void *sptr, int ilevel,
Lev Walkin41ba1f22004-09-14 12:46:35 +0000306 asn_app_consume_bytes_f *cb, void *app_key) {
307 const REAL_t *st = (const REAL_t *)sptr;
Lev Walkin8e8078a2004-09-26 13:10:40 +0000308 ssize_t ret;
Lev Walkin41ba1f22004-09-14 12:46:35 +0000309 double d;
Lev Walkin41ba1f22004-09-14 12:46:35 +0000310
311 (void)td; /* Unused argument */
312 (void)ilevel; /* Unused argument */
313
Lev Walkina9cc46e2004-09-22 16:06:28 +0000314 if(!st || !st->buf)
Lev Walkin8e8078a2004-09-26 13:10:40 +0000315 ret = cb("<absent>", 8, app_key);
Lev Walkin5e033762004-09-29 13:26:15 +0000316 else if(asn_REAL2double(st, &d))
Lev Walkin8e8078a2004-09-26 13:10:40 +0000317 ret = cb("<error>", 7, app_key);
318 else
319 ret = REAL__dump(d, 0, cb, app_key);
Lev Walkin41ba1f22004-09-14 12:46:35 +0000320
Lev Walkin8e8078a2004-09-26 13:10:40 +0000321 return (ret < 0) ? -1 : 0;
Lev Walkina9cc46e2004-09-22 16:06:28 +0000322}
Lev Walkin41ba1f22004-09-14 12:46:35 +0000323
Lev Walkincd2f48e2017-08-10 02:14:59 -0700324int
325REAL_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
326 const void *bptr) {
327 const REAL_t *a = aptr;
328 const REAL_t *b = bptr;
329
330 (void)td;
331
332 if(a && b) {
333 double adbl, bdbl;
334 int ra, rb;
335 ra = asn_REAL2double(a, &adbl);
336 rb = asn_REAL2double(b, &bdbl);
337 if(ra == 0 && rb == 0) {
Lev Walkineff98a52017-09-13 22:24:35 +0000338 if(asn_isnan(adbl)) {
339 if(asn_isnan(bdbl)) {
Lev Walkincd2f48e2017-08-10 02:14:59 -0700340 return 0;
341 } else {
342 return -1;
343 }
Lev Walkineff98a52017-09-13 22:24:35 +0000344 } else if(asn_isnan(bdbl)) {
Lev Walkincd2f48e2017-08-10 02:14:59 -0700345 return 1;
346 }
347 /* Value comparison. */
348 if(adbl < bdbl) {
349 return -1;
350 } else if(adbl > bdbl) {
351 return 1;
352 } else {
353 return 0;
354 }
355 } else if(ra) {
356 return -1;
357 } else {
358 return 1;
359 }
360 } else if(!a) {
361 return -1;
362 } else {
363 return 1;
364 }
365}
366
Lev Walkina9cc46e2004-09-22 16:06:28 +0000367asn_enc_rval_t
Lev Walkin5e033762004-09-29 13:26:15 +0000368REAL_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
Lev Walkina9cc46e2004-09-22 16:06:28 +0000369 int ilevel, enum xer_encoder_flags_e flags,
370 asn_app_consume_bytes_f *cb, void *app_key) {
371 REAL_t *st = (REAL_t *)sptr;
372 asn_enc_rval_t er;
373 double d;
374
375 (void)ilevel;
376
Lev Walkin5e033762004-09-29 13:26:15 +0000377 if(!st || !st->buf || asn_REAL2double(st, &d))
Lev Walkin7c1dc052016-03-14 03:08:15 -0700378 ASN__ENCODE_FAILED;
Lev Walkina9cc46e2004-09-22 16:06:28 +0000379
380 er.encoded = REAL__dump(d, flags & XER_F_CANONICAL, cb, app_key);
Lev Walkin7c1dc052016-03-14 03:08:15 -0700381 if(er.encoded < 0) ASN__ENCODE_FAILED;
Lev Walkina9cc46e2004-09-22 16:06:28 +0000382
Lev Walkin7c1dc052016-03-14 03:08:15 -0700383 ASN__ENCODED_OK(er);
Lev Walkin41ba1f22004-09-14 12:46:35 +0000384}
385
Lev Walkin5f560912004-10-21 13:37:57 +0000386
387/*
388 * Decode the chunk of XML text encoding REAL.
389 */
Lev Walkin0fab1a62005-03-09 22:19:25 +0000390static enum xer_pbd_rval
391REAL__xer_body_decode(asn_TYPE_descriptor_t *td, void *sptr, const void *chunk_buf, size_t chunk_size) {
Lev Walkin8471cec2004-10-21 14:02:19 +0000392 REAL_t *st = (REAL_t *)sptr;
Lev Walkin5f560912004-10-21 13:37:57 +0000393 double value;
Lev Walkin0fab1a62005-03-09 22:19:25 +0000394 const char *xerdata = (const char *)chunk_buf;
Lev Walkin5f560912004-10-21 13:37:57 +0000395 char *endptr = 0;
396 char *b;
397
Lev Walkine0b56e02005-02-25 12:10:27 +0000398 (void)td;
399
Lev Walkin0fab1a62005-03-09 22:19:25 +0000400 if(!chunk_size) return XPBD_BROKEN_ENCODING;
Lev Walkin5f560912004-10-21 13:37:57 +0000401
402 /*
403 * Decode an XMLSpecialRealValue: <MINUS-INFINITY>, etc.
404 */
405 if(xerdata[0] == 0x3c /* '<' */) {
406 size_t i;
407 for(i = 0; i < sizeof(specialRealValue)
408 / sizeof(specialRealValue[0]); i++) {
409 struct specialRealValue_s *srv = &specialRealValue[i];
Lev Walkin1aea6982004-10-26 09:35:25 +0000410 double dv;
411
Lev Walkin5f560912004-10-21 13:37:57 +0000412 if(srv->length != chunk_size
413 || memcmp(srv->string, chunk_buf, chunk_size))
414 continue;
415
Lev Walkin1aea6982004-10-26 09:35:25 +0000416 /*
417 * It could've been done using
418 * (double)srv->dv / real_zero,
419 * but it summons fp exception on some platforms.
420 */
421 switch(srv->dv) {
422 case -1: dv = - INFINITY; break;
423 case 0: dv = NAN; break;
424 case 1: dv = INFINITY; break;
Lev Walkin0fab1a62005-03-09 22:19:25 +0000425 default: return XPBD_SYSTEM_FAILURE;
Lev Walkin1aea6982004-10-26 09:35:25 +0000426 }
427
Lev Walkin0fab1a62005-03-09 22:19:25 +0000428 if(asn_double2REAL(st, dv))
429 return XPBD_SYSTEM_FAILURE;
Lev Walkin5f560912004-10-21 13:37:57 +0000430
Lev Walkin0fab1a62005-03-09 22:19:25 +0000431 return XPBD_BODY_CONSUMED;
Lev Walkin5f560912004-10-21 13:37:57 +0000432 }
433 ASN_DEBUG("Unknown XMLSpecialRealValue");
Lev Walkin0fab1a62005-03-09 22:19:25 +0000434 return XPBD_BROKEN_ENCODING;
Lev Walkin5f560912004-10-21 13:37:57 +0000435 }
436
437 /*
438 * Copy chunk into the nul-terminated string, and run strtod.
439 */
Lev Walkin8471cec2004-10-21 14:02:19 +0000440 b = (char *)MALLOC(chunk_size + 1);
Lev Walkin0fab1a62005-03-09 22:19:25 +0000441 if(!b) return XPBD_SYSTEM_FAILURE;
Lev Walkin5f560912004-10-21 13:37:57 +0000442 memcpy(b, chunk_buf, chunk_size);
Lev Walkin8471cec2004-10-21 14:02:19 +0000443 b[chunk_size] = 0; /* nul-terminate */
Lev Walkin5f560912004-10-21 13:37:57 +0000444
445 value = strtod(b, &endptr);
Lev Walkin419f6752006-09-13 04:02:00 +0000446 FREEMEM(b);
Lev Walkin0fab1a62005-03-09 22:19:25 +0000447 if(endptr == b) return XPBD_BROKEN_ENCODING;
Lev Walkin5f560912004-10-21 13:37:57 +0000448
449 if(asn_double2REAL(st, value))
Lev Walkin0fab1a62005-03-09 22:19:25 +0000450 return XPBD_SYSTEM_FAILURE;
Lev Walkin5f560912004-10-21 13:37:57 +0000451
Lev Walkin0fab1a62005-03-09 22:19:25 +0000452 return XPBD_BODY_CONSUMED;
Lev Walkin5f560912004-10-21 13:37:57 +0000453}
454
455asn_dec_rval_t
Lev Walkinafbf2a92017-09-12 23:30:27 -0700456REAL_decode_xer(const asn_codec_ctx_t *opt_codec_ctx,
Lev Walkin5f560912004-10-21 13:37:57 +0000457 asn_TYPE_descriptor_t *td, void **sptr, const char *opt_mname,
Lev Walkin8c3b8542005-03-10 18:52:02 +0000458 const void *buf_ptr, size_t size) {
Lev Walkin5f560912004-10-21 13:37:57 +0000459
460 return xer_decode_primitive(opt_codec_ctx, td,
Lev Walkin8471cec2004-10-21 14:02:19 +0000461 sptr, sizeof(REAL_t), opt_mname,
Lev Walkin5f560912004-10-21 13:37:57 +0000462 buf_ptr, size, REAL__xer_body_decode);
463}
464
Lev Walkin41ba1f22004-09-14 12:46:35 +0000465int
Lev Walkin5e033762004-09-29 13:26:15 +0000466asn_REAL2double(const REAL_t *st, double *dbl_value) {
Lev Walkina9cc46e2004-09-22 16:06:28 +0000467 unsigned int octv;
Lev Walkin41ba1f22004-09-14 12:46:35 +0000468
469 if(!st || !st->buf) {
470 errno = EINVAL;
471 return -1;
472 }
473
474 if(st->size == 0) {
475 *dbl_value = 0;
476 return 0;
477 }
478
479 octv = st->buf[0]; /* unsigned byte */
480
481 switch(octv & 0xC0) {
Lev Walkin5fda7d52012-01-09 03:20:19 -0800482 case 0x40: /* X.690: 8.5.6 a) => 8.5.9 */
Lev Walkin41ba1f22004-09-14 12:46:35 +0000483 /* "SpecialRealValue" */
484
485 /* Be liberal in what you accept...
Lev Walkin749916f2012-01-07 17:03:39 -0800486 * http://en.wikipedia.org/wiki/Robustness_principle
Lev Walkin41ba1f22004-09-14 12:46:35 +0000487 if(st->size != 1) ...
488 */
489
490 switch(st->buf[0]) {
491 case 0x40: /* 01000000: PLUS-INFINITY */
Lev Walkin1aea6982004-10-26 09:35:25 +0000492 *dbl_value = INFINITY;
Lev Walkin41ba1f22004-09-14 12:46:35 +0000493 return 0;
494 case 0x41: /* 01000001: MINUS-INFINITY */
Lev Walkin1aea6982004-10-26 09:35:25 +0000495 *dbl_value = - INFINITY;
Lev Walkin41ba1f22004-09-14 12:46:35 +0000496 return 0;
Lev Walkin41ba1f22004-09-14 12:46:35 +0000497 case 0x42: /* 01000010: NOT-A-NUMBER */
498 *dbl_value = NAN;
499 return 0;
500 case 0x43: /* 01000011: minus zero */
Lev Walkin2a789d92004-09-27 21:36:59 +0000501 *dbl_value = -0.0;
Lev Walkin41ba1f22004-09-14 12:46:35 +0000502 return 0;
503 }
504
505 errno = EINVAL;
506 return -1;
Lev Walkin0959ffb2011-06-25 15:48:52 -0700507 case 0x00: { /* X.690: 8.5.7 */
Lev Walkin41ba1f22004-09-14 12:46:35 +0000508 /*
Lev Walkin5fda7d52012-01-09 03:20:19 -0800509 * Decimal. NR{1,2,3} format from ISO 6093.
510 * NR1: [ ]*[+-]?[0-9]+
511 * NR2: [ ]*[+-]?([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)
512 * NR3: [ ]*[+-]?([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)[Ee][+-]?[0-9]+
Lev Walkin41ba1f22004-09-14 12:46:35 +0000513 */
514 double d;
Lev Walkin5fda7d52012-01-09 03:20:19 -0800515 char *buf;
516 char *endptr;
517 int used_malloc = 0;
Lev Walkin41ba1f22004-09-14 12:46:35 +0000518
Lev Walkin5fda7d52012-01-09 03:20:19 -0800519 if(octv == 0 || (octv & 0x3C)) {
Lev Walkin0959ffb2011-06-25 15:48:52 -0700520 /* Remaining values of bits 6 to 1 are Reserved. */
521 errno = EINVAL;
522 return -1;
523 }
Lev Walkin41ba1f22004-09-14 12:46:35 +0000524
Lev Walkin53e5ae62017-08-23 10:56:19 -0700525 /* 1. By contract, an input buffer should be '\0'-terminated.
Lev Walkin5fda7d52012-01-09 03:20:19 -0800526 * OCTET STRING decoder ensures that, as is asn_double2REAL().
527 * 2. ISO 6093 specifies COMMA as a possible decimal separator.
528 * However, strtod() can't always deal with COMMA.
529 * So her we fix both by reallocating, copying and fixing.
530 */
Lev Walkin53e5ae62017-08-23 10:56:19 -0700531 if(st->buf[st->size] != '\0' || memchr(st->buf, ',', st->size)) {
Lev Walkin5fda7d52012-01-09 03:20:19 -0800532 uint8_t *p, *end;
533 char *b;
534 if(st->size > 100) {
535 /* Avoid malicious stack overflow in alloca() */
536 buf = (char *)MALLOC(st->size);
537 if(!buf) return -1;
538 used_malloc = 1;
539 } else {
540 buf = alloca(st->size);
541 }
542 b = buf;
543 /* Copy without the first byte and with 0-termination */
544 for(p = st->buf + 1, end = st->buf + st->size;
545 p < end; b++, p++)
546 *b = (*p == ',') ? '.' : *p;
547 *b = '\0';
548 } else {
549 buf = (char *)&st->buf[1];
550 }
551
552 endptr = buf;
553 d = strtod(buf, &endptr);
554 if(*endptr != '\0') {
555 /* Format is not consistent with ISO 6093 */
556 if(used_malloc) FREEMEM(buf);
Lev Walkin0959ffb2011-06-25 15:48:52 -0700557 errno = EINVAL;
558 return -1;
559 }
Lev Walkin5fda7d52012-01-09 03:20:19 -0800560 if(used_malloc) FREEMEM(buf);
Lev Walkineff98a52017-09-13 22:24:35 +0000561 if(asn_isfinite(d)) {
Lev Walkin41ba1f22004-09-14 12:46:35 +0000562 *dbl_value = d;
563 return 0;
564 } else {
565 errno = ERANGE;
Lev Walkin0959ffb2011-06-25 15:48:52 -0700566 return -1;
Lev Walkin41ba1f22004-09-14 12:46:35 +0000567 }
568 }
569 }
570
571 /*
572 * Binary representation.
573 */
574 {
575 double m;
Lev Walkinab1d1e12017-10-03 18:43:12 -0700576 int32_t expval; /* exponent value */
Lev Walkin41ba1f22004-09-14 12:46:35 +0000577 unsigned int elen; /* exponent value length, in octets */
Lev Walkin9c57f332017-09-17 22:30:49 -0700578 int scaleF;
579 int baseF;
Lev Walkin41ba1f22004-09-14 12:46:35 +0000580 uint8_t *ptr;
581 uint8_t *end;
582 int sign;
583
584 switch((octv & 0x30) >> 4) {
585 case 0x00: baseF = 1; break; /* base 2 */
586 case 0x01: baseF = 3; break; /* base 8 */
587 case 0x02: baseF = 4; break; /* base 16 */
588 default:
589 /* Reserved field, can't parse now. */
590 errno = EINVAL;
591 return -1;
592 }
593
594 sign = (octv & 0x40); /* bit 7 */
595 scaleF = (octv & 0x0C) >> 2; /* bits 4 to 3 */
596
Lev Walkin494fb702017-08-07 20:07:00 -0700597 if(st->size <= 1 + (octv & 0x03)) {
Lev Walkin41ba1f22004-09-14 12:46:35 +0000598 errno = EINVAL;
599 return -1;
600 }
601
Lev Walkine78753d2007-06-23 17:02:00 +0000602 elen = (octv & 0x03); /* bits 2 to 1; 8.5.6.4 */
603 if(elen == 0x03) { /* bits 2 to 1 = 11; 8.5.6.4, case d) */
Lev Walkin41ba1f22004-09-14 12:46:35 +0000604 elen = st->buf[1]; /* unsigned binary number */
Lev Walkin494fb702017-08-07 20:07:00 -0700605 if(elen == 0 || st->size <= (2 + elen)) {
Lev Walkin41ba1f22004-09-14 12:46:35 +0000606 errno = EINVAL;
607 return -1;
608 }
Lev Walkine78753d2007-06-23 17:02:00 +0000609 /* FIXME: verify constraints of case d) */
Lev Walkin41ba1f22004-09-14 12:46:35 +0000610 ptr = &st->buf[2];
611 } else {
Lev Walkin41ba1f22004-09-14 12:46:35 +0000612 ptr = &st->buf[1];
613 }
614
615 /* Fetch the multibyte exponent */
616 expval = (int)(*(int8_t *)ptr);
Lev Walkinab1d1e12017-10-03 18:43:12 -0700617 if(elen >= sizeof(expval)-1) {
618 errno = ERANGE;
619 return -1;
620 }
Lev Walkin41ba1f22004-09-14 12:46:35 +0000621 end = ptr + elen + 1;
622 for(ptr++; ptr < end; ptr++)
623 expval = (expval * 256) + *ptr;
624
625 m = 0.0; /* Initial mantissa value */
626
627 /* Okay, the exponent is here. Now, what about mantissa? */
628 end = st->buf + st->size;
Lev Walkin5fda7d52012-01-09 03:20:19 -0800629 for(; ptr < end; ptr++)
630 m = ldexp(m, 8) + *ptr;
Lev Walkin41ba1f22004-09-14 12:46:35 +0000631
Lev Walkin5f560912004-10-21 13:37:57 +0000632 if(0)
Lev Walkinab1d1e12017-10-03 18:43:12 -0700633 ASN_DEBUG("m=%.10f [%08llx], scF=%d, bF=%d, expval=%d, ldexp()=%f, ldexp()=%f\n",
634 m, *(uint64_t*)&m, scaleF, baseF, expval,
Lev Walkin41ba1f22004-09-14 12:46:35 +0000635 ldexp(m, expval * baseF + scaleF),
Lev Walkin77aa90f2005-04-28 22:56:36 +0000636 ldexp(m, scaleF) * pow(pow(2, baseF), expval)
Lev Walkin41ba1f22004-09-14 12:46:35 +0000637 );
638
639 /*
640 * (S * N * 2^F) * B^E
641 * Essentially:
Lev Walkinab1d1e12017-10-03 18:43:12 -0700642 m = ldexp(m, scaleF) * pow(pow(2, baseF), expval);
Lev Walkin41ba1f22004-09-14 12:46:35 +0000643 */
644 m = ldexp(m, expval * baseF + scaleF);
Lev Walkineff98a52017-09-13 22:24:35 +0000645 if(asn_isfinite(m)) {
Lev Walkin41ba1f22004-09-14 12:46:35 +0000646 *dbl_value = sign ? -m : m;
647 } else {
648 errno = ERANGE;
649 return -1;
650 }
651
652 } /* if(binary_format) */
653
654 return 0;
655}
656
657/*
658 * Assume IEEE 754 floating point: standard 64 bit double.
659 * [1 bit sign] [11 bits exponent] [52 bits mantissa]
660 */
661int
Lev Walkin5e033762004-09-29 13:26:15 +0000662asn_double2REAL(REAL_t *st, double dbl_value) {
Lev Walkin41ba1f22004-09-14 12:46:35 +0000663#ifdef WORDS_BIGENDIAN /* Known to be big-endian */
664 int littleEndian = 0;
665#else /* need to test: have no explicit information */
666 unsigned int LE = 1;
667 int littleEndian = *(unsigned char *)&LE;
668#endif
669 uint8_t buf[16]; /* More than enough for 8-byte dbl_value */
670 uint8_t dscr[sizeof(dbl_value)]; /* double value scratch pad */
671 /* Assertion guards: won't even compile, if unexpected double size */
Lev Walkin3f995632017-09-26 18:27:32 -0700672 char assertion_buffer1[9 - sizeof(dbl_value)] CC_NOTUSED;
673 char assertion_buffer2[sizeof(dbl_value) - 7] CC_NOTUSED;
Lev Walkin41ba1f22004-09-14 12:46:35 +0000674 uint8_t *ptr = buf;
675 uint8_t *mstop; /* Last byte of mantissa */
676 unsigned int mval; /* Value of the last byte of mantissa */
677 unsigned int bmsign; /* binary mask with sign */
678 unsigned int buflen;
679 unsigned int accum;
680 int expval;
681
682 if(!st) {
683 errno = EINVAL;
684 return -1;
685 }
686
Lev Walkin057fb732004-09-14 13:58:10 +0000687 /*
688 * ilogb(+-0) returns -INT_MAX or INT_MIN (platform-dependent)
Lev Walkin2f505022005-07-01 08:28:18 +0000689 * ilogb(+-inf) returns INT_MAX, logb(+-inf) returns +inf
Lev Walkin2a789d92004-09-27 21:36:59 +0000690 * ilogb(NaN) returns INT_MIN or INT_MAX (platform-dependent)
Lev Walkin057fb732004-09-14 13:58:10 +0000691 */
Lev Walkin41ba1f22004-09-14 12:46:35 +0000692 expval = ilogb(dbl_value);
Lev Walkin2a789d92004-09-27 21:36:59 +0000693 if(expval <= -INT_MAX /* Also catches +-0 and maybe isnan() */
694 || expval == INT_MAX /* catches isfin() and maybe isnan() */
Lev Walkin41ba1f22004-09-14 12:46:35 +0000695 ) {
696 if(!st->buf || st->size < 2) {
Lev Walkin8e8078a2004-09-26 13:10:40 +0000697 ptr = (uint8_t *)MALLOC(2);
Lev Walkin41ba1f22004-09-14 12:46:35 +0000698 if(!ptr) return -1;
Lev Walkindcae9ce2017-09-18 20:13:36 -0700699 if(st->buf) FREEMEM(st->buf);
Lev Walkin41ba1f22004-09-14 12:46:35 +0000700 st->buf = ptr;
701 }
702 /* fpclassify(3) is not portable yet */
Lev Walkineff98a52017-09-13 22:24:35 +0000703 if(asn_isnan(dbl_value)) {
Lev Walkin2a789d92004-09-27 21:36:59 +0000704 st->buf[0] = 0x42; /* NaN */
705 st->buf[1] = 0;
706 st->size = 1;
Lev Walkineff98a52017-09-13 22:24:35 +0000707 } else if(!asn_isfinite(dbl_value)) {
Lev Walkin7e03db92004-09-14 13:50:21 +0000708 if(copysign(1.0, dbl_value) < 0.0) {
Lev Walkin41ba1f22004-09-14 12:46:35 +0000709 st->buf[0] = 0x41; /* MINUS-INFINITY */
710 } else {
711 st->buf[0] = 0x40; /* PLUS-INFINITY */
712 }
713 st->buf[1] = 0;
714 st->size = 1;
Lev Walkinc51e7d62004-09-27 22:16:18 +0000715 } else {
Lev Walkin5fe72e92012-01-07 17:00:29 -0800716 if(copysign(1.0, dbl_value) >= 0.0) {
Lev Walkinc51e7d62004-09-27 22:16:18 +0000717 /* no content octets: positive zero */
718 st->buf[0] = 0; /* JIC */
719 st->size = 0;
Lev Walkin5fe72e92012-01-07 17:00:29 -0800720 } else {
721 /* Negative zero. #8.5.3, 8.5.9 */
722 st->buf[0] = 0x43;
Lev Walkindcae9ce2017-09-18 20:13:36 -0700723 st->buf[1] = 0;
Lev Walkin5fe72e92012-01-07 17:00:29 -0800724 st->size = 1;
Lev Walkinc51e7d62004-09-27 22:16:18 +0000725 }
Lev Walkin41ba1f22004-09-14 12:46:35 +0000726 }
727 return 0;
728 }
729
730 if(littleEndian) {
731 uint8_t *s = ((uint8_t *)&dbl_value) + sizeof(dbl_value) - 2;
Lev Walkin057fb732004-09-14 13:58:10 +0000732 uint8_t *start = ((uint8_t *)&dbl_value);
Lev Walkin41ba1f22004-09-14 12:46:35 +0000733 uint8_t *d;
734
735 bmsign = 0x80 | ((s[1] >> 1) & 0x40); /* binary mask & - */
Lev Walkin057fb732004-09-14 13:58:10 +0000736 for(mstop = d = dscr; s >= start; d++, s--) {
Lev Walkin41ba1f22004-09-14 12:46:35 +0000737 *d = *s;
738 if(*d) mstop = d;
739 }
740 } else {
741 uint8_t *s = ((uint8_t *)&dbl_value) + 1;
742 uint8_t *end = ((uint8_t *)&dbl_value) + sizeof(double);
743 uint8_t *d;
744
745 bmsign = 0x80 | ((s[-1] >> 1) & 0x40); /* binary mask & - */
746 for(mstop = d = dscr; s < end; d++, s++) {
747 *d = *s;
748 if(*d) mstop = d;
749 }
750 }
751
752 /* Remove parts of the exponent, leave mantissa and explicit 1. */
753 dscr[0] = 0x10 | (dscr[0] & 0x0f);
754
755 /* Adjust exponent in a very unobvious way */
756 expval -= 8 * ((mstop - dscr) + 1) - 4;
757
758 /* This loop ensures DER conformance by forcing mantissa odd: 11.3.1 */
759 mval = *mstop;
760 if(mval && !(mval & 1)) {
Lev Walkin9c57f332017-09-17 22:30:49 -0700761 int shift_count = 1;
762 int ishift;
Lev Walkin41ba1f22004-09-14 12:46:35 +0000763 uint8_t *mptr;
764
765 /*
766 * Figure out what needs to be done to make mantissa odd.
767 */
768 if(!(mval & 0x0f)) /* Speed-up a little */
769 shift_count = 4;
770 while(((mval >> shift_count) & 1) == 0)
771 shift_count++;
772
773 ishift = 8 - shift_count;
774 accum = 0;
775
776 /* Go over the buffer, shifting it shift_count bits right. */
777 for(mptr = dscr; mptr <= mstop; mptr++) {
778 mval = *mptr;
779 *mptr = accum | (mval >> shift_count);
780 accum = mval << ishift;
781 }
782
Lev Walkinb89b3402012-01-09 18:26:30 -0800783 /* Adjust exponent appropriately. */
Lev Walkin41ba1f22004-09-14 12:46:35 +0000784 expval += shift_count;
785 }
786
787 if(expval < 0) {
788 if((expval >> 7) == -1) {
789 *ptr++ = bmsign | 0x00;
790 *ptr++ = expval;
791 } else if((expval >> 15) == -1) {
792 *ptr++ = bmsign | 0x01;
793 *ptr++ = expval >> 8;
794 *ptr++ = expval;
795 } else {
Lev Walkin41ba1f22004-09-14 12:46:35 +0000796 *ptr++ = bmsign | 0x02;
797 *ptr++ = expval >> 16;
798 *ptr++ = expval >> 8;
799 *ptr++ = expval;
800 }
801 } else if(expval <= 0x7f) {
802 *ptr++ = bmsign | 0x00;
803 *ptr++ = expval;
804 } else if(expval <= 0x7fff) {
805 *ptr++ = bmsign | 0x01;
806 *ptr++ = expval >> 8;
807 *ptr++ = expval;
808 } else {
809 assert(expval <= 0x7fffff);
810 *ptr++ = bmsign | 0x02;
811 *ptr++ = expval >> 16;
812 *ptr++ = expval >> 8;
813 *ptr++ = expval;
814 }
815
816 buflen = (mstop - dscr) + 1;
817 memcpy(ptr, dscr, buflen);
818 ptr += buflen;
819 buflen = ptr - buf;
820
Lev Walkinc17d90f2005-01-17 14:32:45 +0000821 ptr = (uint8_t *)MALLOC(buflen + 1);
Lev Walkin41ba1f22004-09-14 12:46:35 +0000822 if(!ptr) return -1;
823
824 memcpy(ptr, buf, buflen);
825 buf[buflen] = 0; /* JIC */
826
827 if(st->buf) FREEMEM(st->buf);
828 st->buf = ptr;
829 st->size = buflen;
830
831 return 0;
832}
Lev Walkin41d972b2017-08-23 23:30:59 -0700833
834#ifndef ASN_DISABLE_PER_SUPPORT
835
836asn_dec_rval_t
Lev Walkinafbf2a92017-09-12 23:30:27 -0700837REAL_decode_uper(const asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
Lev Walkin41d972b2017-08-23 23:30:59 -0700838 const asn_per_constraints_t *constraints, void **sptr,
839 asn_per_data_t *pd) {
840 (void)constraints; /* No PER visible constraints */
841 return OCTET_STRING_decode_uper(opt_codec_ctx, td, 0, sptr, pd);
842}
843
844asn_enc_rval_t
845REAL_encode_uper(asn_TYPE_descriptor_t *td,
846 const asn_per_constraints_t *constraints, void *sptr,
847 asn_per_outp_t *po) {
848 (void)constraints; /* No PER visible constraints */
849 return OCTET_STRING_encode_uper(td, 0, sptr, po);
850}
851
852#endif /* ASN_DISABLE_PER_SUPPORT */
Lev Walkina5972be2017-09-29 23:15:58 -0700853
854
855asn_random_fill_result_t
856REAL_random_fill(const asn_TYPE_descriptor_t *td, void **sptr,
857 const asn_encoding_constraints_t *constraints,
858 size_t max_length) {
859 asn_random_fill_result_t result_ok = {ARFILL_OK, 1};
860 asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0};
861 asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
Lev Walkinab1d1e12017-10-03 18:43:12 -0700862 static const double values[] = {
863 0, -0.0, -1, 1, -M_E, M_E, -3.14, 3.14, -M_PI, M_PI, -255, 255,
864 /* 2^51 */
865 -2251799813685248.0, 2251799813685248.0,
866 /* 2^52 */
867 -4503599627370496.0, 4503599627370496.0,
868 /* 2^100 */
869 -1267650600228229401496703205376.0, 1267650600228229401496703205376.0,
Lev Walkin4ca41492017-10-03 20:29:54 -0700870#if __STDC_VERSION__ >= 199901L
871 -MAXFLOAT, MAXFLOAT,
872#endif
873 INFINITY, -INFINITY, NAN};
Lev Walkina5972be2017-09-29 23:15:58 -0700874 REAL_t *st;
875 double d;
876
877 (void)constraints;
878
879 if(max_length == 0) return result_skipped;
880
881 d = values[asn_random_between(0, sizeof(values) / sizeof(values[0]) - 1)];
882
883 if(*sptr) {
884 st = *sptr;
885 } else {
886 st = (REAL_t*)(*sptr = CALLOC(1, sizeof(REAL_t)));
887 if(!st) {
888 return result_failed;
889 }
890 }
891
892 if(asn_double2REAL(st, d)) {
893 if(st == *sptr) {
894 ASN_STRUCT_RESET(*td, st);
895 } else {
896 ASN_STRUCT_FREE(*td, st);
897 }
898 return result_failed;
899 }
900
901 result_ok.length = st->size;
902 return result_ok;
903}
Lev Walkinab1d1e12017-10-03 18:43:12 -0700904