portability fixes
diff --git a/skeletons/RELATIVE-OID.c b/skeletons/RELATIVE-OID.c
index b0f6f64..70291e2 100644
--- a/skeletons/RELATIVE-OID.c
+++ b/skeletons/RELATIVE-OID.c
@@ -220,7 +220,7 @@
/*
* Replace buffer.
*/
- roid->size = bp - buf;
+ roid->size = (int)(bp - buf);
bp = roid->buf;
roid->buf = buf;
if(bp) FREEMEM(bp);
diff --git a/skeletons/asn_codecs_prim.c b/skeletons/asn_codecs_prim.c
index 5fe09ad..42f5a40 100644
--- a/skeletons/asn_codecs_prim.c
+++ b/skeletons/asn_codecs_prim.c
@@ -55,10 +55,19 @@
return rval;
}
+ st->size = (int)length;
+ /* The following better be optimized away. */
+ if(sizeof(st->size) != sizeof(length)
+ && (ber_tlv_len_t)st->size != length) {
+ st->size = 0;
+ rval.code = RC_FAIL;
+ rval.consumed = 0;
+ return rval;
+ }
+
st->buf = (uint8_t *)MALLOC(length + 1);
- if(st->buf) {
- st->size = length;
- } else {
+ if(!st->buf) {
+ st->size = 0;
rval.code = RC_FAIL;
rval.consumed = 0;
return rval;
@@ -146,14 +155,14 @@
};
-static int
+static ssize_t
xer_decode__unexpected_tag(void *key, void *chunk_buf, size_t chunk_size) {
struct xdp_arg_s *arg = (struct xdp_arg_s *)key;
ssize_t decoded;
if(arg->decoded_something) {
if(xer_is_whitespace(chunk_buf, chunk_size))
- return chunk_size;
+ return 0; /* Skip it. */
/*
* Decoding was done once already. Prohibit doing it again.
*/
diff --git a/skeletons/asn_system.h b/skeletons/asn_system.h
index 4626532..5a5eb9b 100644
--- a/skeletons/asn_system.h
+++ b/skeletons/asn_system.h
@@ -19,12 +19,15 @@
#include <stdarg.h> /* For va_start */
#include <stddef.h> /* for offsetof and ptrdiff_t */
+#ifdef WIN32
+
+#define snprintf _snprintf
+#define vsnprintf _vsnprintf
+#define alloca(size) _alloca(size)
+
+#else /* !WIN32 */
+
#include <inttypes.h> /* C99 specifies this file */
-
-#if defined(sun)
-#include <ieeefp.h> /* for finite(3) */
-#endif
-
/*
* 1. Earlier FreeBSD version didn't have <stdint.h>,
* but <inttypes.h> was present.
@@ -34,15 +37,12 @@
#if (!defined(__FreeBSD__) || !defined(_SYS_INTTYPES_H_))
#if defined(sun)
#include <alloca.h> /* For alloca(3) */
+#include <ieeefp.h> /* for finite(3) */
#else
#include <stdint.h> /* SUSv2+ and C99 specify this file, for uintXX_t */
-#endif
+#endif /* defined(sun) */
#endif
-#ifdef WIN32
-#define snprintf _snprintf
-#define vsnprintf _vsnprintf
-#define alloca(size) _alloca(size)
#endif /* WIN32 */
#ifndef __GNUC__
diff --git a/skeletons/ber_tlv_length.c b/skeletons/ber_tlv_length.c
index 1534d9b..4f1ea88 100644
--- a/skeletons/ber_tlv_length.c
+++ b/skeletons/ber_tlv_length.c
@@ -155,7 +155,7 @@
if(len <= 127) {
/* Encoded in 1 octet */
- if(size) *buf = len;
+ if(size) *buf = (uint8_t)len;
return 1;
}
@@ -172,14 +172,14 @@
if(size < required_size)
return required_size + 1;
- *buf++ = 0x80 | required_size; /* Length of the encoding */
+ *buf++ = (uint8_t)(0x80 | required_size); /* Length of the encoding */
/*
* Produce the len encoding, space permitting.
*/
end = buf + required_size;
for(i -= 8; buf < end; i -= 8, buf++)
- *buf = (len >> i);
+ *buf = (uint8_t)(len >> i);
return required_size + 1;
}
diff --git a/skeletons/xer_decoder.c b/skeletons/xer_decoder.c
index 0de6e33..07a1936 100644
--- a/skeletons/xer_decoder.c
+++ b/skeletons/xer_decoder.c
@@ -276,7 +276,7 @@
*/
if(opt_unexpected_tag_decoder
&& opt_unexpected_tag_decoder(struct_key,
- buf_ptr, ch_size) == 0) {
+ buf_ptr, ch_size) >= 0) {
/* Tag's processed fine */
ADVANCE(ch_size);
if(!ctx->phase) {