Commit eff98a50 authored by Lev Walkin's avatar Lev Walkin

fixed under freebsd and clang

parent dfbff614
...@@ -15,6 +15,24 @@ ...@@ -15,6 +15,24 @@
#include <OCTET_STRING.h> #include <OCTET_STRING.h>
#include <math.h> #include <math.h>
#if defined(__clang__)
/*
* isnan() is defined using generic selections and won't compile in
* strict C89 mode because of too fancy system's standard library.
* However, prior to C11 the math had a perfectly working isnan()
* in the math library.
* Disable generic selection warning so we can test C89 mode with newer libc.
*/
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc11-extensions"
static int asn_isnan(double d) {
return isnan(d);
}
#pragma clang diagnostic pop
#else
#define asn_isnan(v) isnan(v)
#endif /* generic selections */
/* /*
* NativeReal basic type description. * NativeReal basic type description.
*/ */
...@@ -359,13 +377,13 @@ NativeReal_compare(const asn_TYPE_descriptor_t *td, const void *aptr, ...@@ -359,13 +377,13 @@ NativeReal_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
if(a && b) { if(a && b) {
/* NaN sorted above everything else */ /* NaN sorted above everything else */
if(isnan(*a)) { if(asn_isnan(*a)) {
if(isnan(*b)) { if(asn_isnan(*b)) {
return 0; return 0;
} else { } else {
return -1; return -1;
} }
} else if(isnan(*b)) { } else if(asn_isnan(*b)) {
return 1; return 1;
} }
/* Value comparison. */ /* Value comparison. */
......
...@@ -29,11 +29,36 @@ static volatile double real_zero GCC_NOTUSED = 0.0; ...@@ -29,11 +29,36 @@ static volatile double real_zero GCC_NOTUSED = 0.0;
#define INFINITY (1.0/real_zero) #define INFINITY (1.0/real_zero)
#endif #endif
#if defined(__clang__)
/*
* isnan() is defined using generic selections and won't compile in
* strict C89 mode because of too fancy system's standard library.
* However, prior to C11 the math had a perfectly working isnan()
* in the math library.
* Disable generic selection warning so we can test C89 mode with newer libc.
*/
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wc11-extensions"
static int asn_isnan(double d) {
return isnan(d);
}
static int asn_isfinite(double d) {
#ifdef isfinite
return isfinite(d); /* ISO C99 */
#else
return finite(d); /* Deprecated on Mac OS X 10.9 */
#endif
}
#pragma clang diagnostic pop
#else /* !clang */
#define asn_isnan(v) isnan(v)
#ifdef isfinite #ifdef isfinite
#define _asn_isfinite(d) isfinite(d) /* ISO C99 */ #define asn_isfinite(d) isfinite(d) /* ISO C99 */
#else #else
#define _asn_isfinite(d) finite(d) /* Deprecated on Mac OS X 10.9 */ #define asn_isfinite(d) finite(d) /* Deprecated on Mac OS X 10.9 */
#endif #endif
#endif /* clang */
/* /*
* REAL basic type description. * REAL basic type description.
...@@ -110,11 +135,11 @@ REAL__dump(double d, int canonical, asn_app_consume_bytes_f *cb, void *app_key) ...@@ -110,11 +135,11 @@ REAL__dump(double d, int canonical, asn_app_consume_bytes_f *cb, void *app_key)
* Check whether it is a special value. * Check whether it is a special value.
*/ */
/* fpclassify(3) is not portable yet */ /* fpclassify(3) is not portable yet */
if(isnan(d)) { if(asn_isnan(d)) {
buf = specialRealValue[SRV__NOT_A_NUMBER].string; buf = specialRealValue[SRV__NOT_A_NUMBER].string;
buflen = specialRealValue[SRV__NOT_A_NUMBER].length; buflen = specialRealValue[SRV__NOT_A_NUMBER].length;
return (cb(buf, buflen, app_key) < 0) ? -1 : buflen; return (cb(buf, buflen, app_key) < 0) ? -1 : buflen;
} else if(!_asn_isfinite(d)) { } else if(!asn_isfinite(d)) {
if(copysign(1.0, d) < 0.0) { if(copysign(1.0, d) < 0.0) {
buf = specialRealValue[SRV__MINUS_INFINITY].string; buf = specialRealValue[SRV__MINUS_INFINITY].string;
buflen = specialRealValue[SRV__MINUS_INFINITY].length; buflen = specialRealValue[SRV__MINUS_INFINITY].length;
...@@ -311,13 +336,13 @@ REAL_compare(const asn_TYPE_descriptor_t *td, const void *aptr, ...@@ -311,13 +336,13 @@ REAL_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
ra = asn_REAL2double(a, &adbl); ra = asn_REAL2double(a, &adbl);
rb = asn_REAL2double(b, &bdbl); rb = asn_REAL2double(b, &bdbl);
if(ra == 0 && rb == 0) { if(ra == 0 && rb == 0) {
if(isnan(adbl)) { if(asn_isnan(adbl)) {
if(isnan(bdbl)) { if(asn_isnan(bdbl)) {
return 0; return 0;
} else { } else {
return -1; return -1;
} }
} else if(isnan(bdbl)) { } else if(asn_isnan(bdbl)) {
return 1; return 1;
} }
/* Value comparison. */ /* Value comparison. */
...@@ -535,7 +560,7 @@ asn_REAL2double(const REAL_t *st, double *dbl_value) { ...@@ -535,7 +560,7 @@ asn_REAL2double(const REAL_t *st, double *dbl_value) {
return -1; return -1;
} }
if(used_malloc) FREEMEM(buf); if(used_malloc) FREEMEM(buf);
if(_asn_isfinite(d)) { if(asn_isfinite(d)) {
*dbl_value = d; *dbl_value = d;
return 0; return 0;
} else { } else {
...@@ -615,7 +640,7 @@ asn_REAL2double(const REAL_t *st, double *dbl_value) { ...@@ -615,7 +640,7 @@ asn_REAL2double(const REAL_t *st, double *dbl_value) {
m = ldexp(m, scaleF) * pow(pow(2, base), expval); m = ldexp(m, scaleF) * pow(pow(2, base), expval);
*/ */
m = ldexp(m, expval * baseF + scaleF); m = ldexp(m, expval * baseF + scaleF);
if(_asn_isfinite(m)) { if(asn_isfinite(m)) {
*dbl_value = sign ? -m : m; *dbl_value = sign ? -m : m;
} else { } else {
errno = ERANGE; errno = ERANGE;
...@@ -672,11 +697,11 @@ asn_double2REAL(REAL_t *st, double dbl_value) { ...@@ -672,11 +697,11 @@ asn_double2REAL(REAL_t *st, double dbl_value) {
st->buf = ptr; st->buf = ptr;
} }
/* fpclassify(3) is not portable yet */ /* fpclassify(3) is not portable yet */
if(isnan(dbl_value)) { if(asn_isnan(dbl_value)) {
st->buf[0] = 0x42; /* NaN */ st->buf[0] = 0x42; /* NaN */
st->buf[1] = 0; st->buf[1] = 0;
st->size = 1; st->size = 1;
} else if(!_asn_isfinite(dbl_value)) { } else if(!asn_isfinite(dbl_value)) {
if(copysign(1.0, dbl_value) < 0.0) { if(copysign(1.0, dbl_value) < 0.0) {
st->buf[0] = 0x41; /* MINUS-INFINITY */ st->buf[0] = 0x41; /* MINUS-INFINITY */
} else { } else {
......
...@@ -134,8 +134,6 @@ CHOICE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *t ...@@ -134,8 +134,6 @@ CHOICE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *t
asn_CHOICE_specifics_t *specs = (asn_CHOICE_specifics_t *)td->specifics; asn_CHOICE_specifics_t *specs = (asn_CHOICE_specifics_t *)td->specifics;
asn_TYPE_member_t *elements = td->elements; asn_TYPE_member_t *elements = td->elements;
(void)specs;
/* /*
* Parts of the structure being constructed. * Parts of the structure being constructed.
*/ */
...@@ -180,7 +178,8 @@ CHOICE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *t ...@@ -180,7 +178,8 @@ CHOICE_decode_oer(const asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *t
do { do {
const asn_TYPE_tag2member_t *t2m; const asn_TYPE_tag2member_t *t2m;
asn_TYPE_tag2member_t key = {tlv_tag, 0, 0, 0}; asn_TYPE_tag2member_t key = {0, 0, 0, 0};
key.el_tag = tlv_tag;
t2m = (const asn_TYPE_tag2member_t *)bsearch( t2m = (const asn_TYPE_tag2member_t *)bsearch(
&key, specs->tag2el, specs->tag2el_count, &key, specs->tag2el, specs->tag2el_count,
......
...@@ -312,7 +312,9 @@ SEQUENCE_decode_ber(const asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t ...@@ -312,7 +312,9 @@ SEQUENCE_decode_ber(const asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t
* sorted array of tags. * sorted array of tags.
*/ */
const asn_TYPE_tag2member_t *t2m; const asn_TYPE_tag2member_t *t2m;
asn_TYPE_tag2member_t key = {tlv_tag, edx, 0, 0}; asn_TYPE_tag2member_t key = {0, 0, 0, 0};
key.el_tag = tlv_tag;
key.el_no = edx;
t2m = (const asn_TYPE_tag2member_t *)bsearch(&key, t2m = (const asn_TYPE_tag2member_t *)bsearch(&key,
specs->tag2el, specs->tag2el_count, specs->tag2el, specs->tag2el_count,
sizeof(specs->tag2el[0]), _t2e_cmp); sizeof(specs->tag2el[0]), _t2e_cmp);
......
...@@ -63,6 +63,8 @@ ...@@ -63,6 +63,8 @@
*/ */
static ssize_t static ssize_t
oer_fetch_quantity(const void *ptr, size_t size, size_t *qty_r) { oer_fetch_quantity(const void *ptr, size_t size, size_t *qty_r) {
const uint8_t *b;
const uint8_t *bend;
size_t len = 0; size_t len = 0;
size_t qty; size_t qty;
...@@ -77,15 +79,13 @@ oer_fetch_quantity(const void *ptr, size_t size, size_t *qty_r) { ...@@ -77,15 +79,13 @@ oer_fetch_quantity(const void *ptr, size_t size, size_t *qty_r) {
return 0; return 0;
} }
const uint8_t *b = (const uint8_t *)ptr + len_len; b = (const uint8_t *)ptr + len_len;
const uint8_t *bend = b + len; bend = b + len;
/* Skip the leading 0-bytes */ /* Skip the leading 0-bytes */
for(; b < bend && *b == 0; b++) { for(; b < bend && *b == 0; b++) {
} }
if((bend - b) > (ssize_t)sizeof(size_t)) { if((bend - b) > (ssize_t)sizeof(size_t)) {
/* Length is not representable by the native size_t type */ /* Length is not representable by the native size_t type */
*qty_r = 0; *qty_r = 0;
...@@ -261,8 +261,9 @@ SET_OF_encode_oer(asn_TYPE_descriptor_t *td, ...@@ -261,8 +261,9 @@ SET_OF_encode_oer(asn_TYPE_descriptor_t *td,
} }
{ {
asn_enc_rval_t erval = {computed_size, 0, 0}; asn_enc_rval_t erval;
return erval; erval.encoded = computed_size;
ASN__ENCODED_OK(erval);
} }
} }
......
...@@ -67,7 +67,7 @@ static void junk_bytes_with_probability(uint8_t *, size_t, double prob); ...@@ -67,7 +67,7 @@ static void junk_bytes_with_probability(uint8_t *, size_t, double prob);
#endif #endif
/* Debug output function */ /* Debug output function */
static inline void static void
DEBUG(const char *fmt, ...) { DEBUG(const char *fmt, ...) {
va_list ap; va_list ap;
if(!opt_debug) return; if(!opt_debug) return;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment