fixed under freebsd and clang

This commit is contained in:
Lev Walkin 2017-09-13 22:24:35 +00:00
parent dfbff614e3
commit eff98a506c
6 changed files with 70 additions and 25 deletions

View File

@ -15,6 +15,24 @@
#include <OCTET_STRING.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.
*/
@ -359,13 +377,13 @@ NativeReal_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
if(a && b) {
/* NaN sorted above everything else */
if(isnan(*a)) {
if(isnan(*b)) {
if(asn_isnan(*a)) {
if(asn_isnan(*b)) {
return 0;
} else {
return -1;
}
} else if(isnan(*b)) {
} else if(asn_isnan(*b)) {
return 1;
}
/* Value comparison. */

View File

@ -29,11 +29,36 @@ static volatile double real_zero GCC_NOTUSED = 0.0;
#define INFINITY (1.0/real_zero)
#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
#define _asn_isfinite(d) isfinite(d) /* ISO C99 */
return isfinite(d); /* ISO C99 */
#else
#define _asn_isfinite(d) finite(d) /* Deprecated on Mac OS X 10.9 */
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
#define asn_isfinite(d) isfinite(d) /* ISO C99 */
#else
#define asn_isfinite(d) finite(d) /* Deprecated on Mac OS X 10.9 */
#endif
#endif /* clang */
/*
* REAL basic type description.
@ -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.
*/
/* fpclassify(3) is not portable yet */
if(isnan(d)) {
if(asn_isnan(d)) {
buf = specialRealValue[SRV__NOT_A_NUMBER].string;
buflen = specialRealValue[SRV__NOT_A_NUMBER].length;
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) {
buf = specialRealValue[SRV__MINUS_INFINITY].string;
buflen = specialRealValue[SRV__MINUS_INFINITY].length;
@ -311,13 +336,13 @@ REAL_compare(const asn_TYPE_descriptor_t *td, const void *aptr,
ra = asn_REAL2double(a, &adbl);
rb = asn_REAL2double(b, &bdbl);
if(ra == 0 && rb == 0) {
if(isnan(adbl)) {
if(isnan(bdbl)) {
if(asn_isnan(adbl)) {
if(asn_isnan(bdbl)) {
return 0;
} else {
return -1;
}
} else if(isnan(bdbl)) {
} else if(asn_isnan(bdbl)) {
return 1;
}
/* Value comparison. */
@ -535,7 +560,7 @@ asn_REAL2double(const REAL_t *st, double *dbl_value) {
return -1;
}
if(used_malloc) FREEMEM(buf);
if(_asn_isfinite(d)) {
if(asn_isfinite(d)) {
*dbl_value = d;
return 0;
} else {
@ -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, expval * baseF + scaleF);
if(_asn_isfinite(m)) {
if(asn_isfinite(m)) {
*dbl_value = sign ? -m : m;
} else {
errno = ERANGE;
@ -672,11 +697,11 @@ asn_double2REAL(REAL_t *st, double dbl_value) {
st->buf = ptr;
}
/* fpclassify(3) is not portable yet */
if(isnan(dbl_value)) {
if(asn_isnan(dbl_value)) {
st->buf[0] = 0x42; /* NaN */
st->buf[1] = 0;
st->size = 1;
} else if(!_asn_isfinite(dbl_value)) {
} else if(!asn_isfinite(dbl_value)) {
if(copysign(1.0, dbl_value) < 0.0) {
st->buf[0] = 0x41; /* MINUS-INFINITY */
} else {

View File

@ -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_TYPE_member_t *elements = td->elements;
(void)specs;
/*
* 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
do {
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(
&key, specs->tag2el, specs->tag2el_count,

View File

@ -312,7 +312,9 @@ SEQUENCE_decode_ber(const asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t
* sorted array of tags.
*/
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,
specs->tag2el, specs->tag2el_count,
sizeof(specs->tag2el[0]), _t2e_cmp);

View File

@ -63,6 +63,8 @@
*/
static ssize_t
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 qty;
@ -77,15 +79,13 @@ oer_fetch_quantity(const void *ptr, size_t size, size_t *qty_r) {
return 0;
}
const uint8_t *b = (const uint8_t *)ptr + len_len;
const uint8_t *bend = b + len;
b = (const uint8_t *)ptr + len_len;
bend = b + len;
/* Skip the leading 0-bytes */
for(; b < bend && *b == 0; b++) {
}
if((bend - b) > (ssize_t)sizeof(size_t)) {
/* Length is not representable by the native size_t type */
*qty_r = 0;
@ -261,8 +261,9 @@ SET_OF_encode_oer(asn_TYPE_descriptor_t *td,
}
{
asn_enc_rval_t erval = {computed_size, 0, 0};
return erval;
asn_enc_rval_t erval;
erval.encoded = computed_size;
ASN__ENCODED_OK(erval);
}
}

View File

@ -67,7 +67,7 @@ static void junk_bytes_with_probability(uint8_t *, size_t, double prob);
#endif
/* Debug output function */
static inline void
static void
DEBUG(const char *fmt, ...) {
va_list ap;
if(!opt_debug) return;