aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configure.ac9
-rw-r--r--skeletons/Makefile.am2
-rw-r--r--skeletons/constr_CHOICE.c9
-rw-r--r--skeletons/constr_SEQUENCE.c9
-rw-r--r--skeletons/constr_SET.c9
-rw-r--r--skeletons/constr_SET_OF.c9
-rw-r--r--skeletons/tests/check-INTEGER.c6
-rw-r--r--skeletons/tests/check-PER-INTEGER.c5
-rw-r--r--skeletons/tests/check-PER.c10
-rw-r--r--skeletons/tests/check-REAL.c16
-rw-r--r--skeletons/tests/check-XER.c8
-rw-r--r--skeletons/tests/check-length.c16
-rw-r--r--skeletons/xer_decoder.c15
-rw-r--r--skeletons/xer_decoder.h7
14 files changed, 75 insertions, 55 deletions
diff --git a/configure.ac b/configure.ac
index 52c592b2..a937bf2b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -75,6 +75,15 @@ AC_ARG_ENABLE(test-Werror,
AC_SUBST(ADD_CFLAGS)
AC_SUBST(TESTSUITE_CFLAGS)
+dnl Skeletons should be very compatible with most of the compilers, hence
+dnl very strict backward compatibility flags.
+SKELETONS_CFLAGS="${ADD_CFLAGS}"
+AX_CHECK_COMPILE_FLAG([-std=c89],
+ [SKELETONS_FLAGS="$SKELETONS_FLAGS -std=c89"])
+AX_CHECK_COMPILE_FLAG([-Wpedantic],
+ [SKELETONS_FLAGS="$SKELETONS_FLAGS -Wpedantic"])
+AC_SUBST(SKELETONS_CFLAGS)
+
dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(sys/param.h)
diff --git a/skeletons/Makefile.am b/skeletons/Makefile.am
index 1882057b..ec904b66 100644
--- a/skeletons/Makefile.am
+++ b/skeletons/Makefile.am
@@ -20,7 +20,7 @@ uninstall-local:
check_LTLIBRARIES = libasn1cskeletons.la
-libasn1cskeletons_la_CFLAGS = $(TESTSUITE_CFLAGS)
+libasn1cskeletons_la_CFLAGS = $(TESTSUITE_CFLAGS) $(SKELETONS_CFLAGS)
libasn1cskeletons_la_SOURCES = \
ANY.c ANY.h \
BIT_STRING.c BIT_STRING.h \
diff --git a/skeletons/constr_CHOICE.c b/skeletons/constr_CHOICE.c
index f366f754..b268788a 100644
--- a/skeletons/constr_CHOICE.c
+++ b/skeletons/constr_CHOICE.c
@@ -640,11 +640,12 @@ CHOICE_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
* Get the next part of the XML stream.
*/
ch_size = xer_next_token(&ctx->context, buf_ptr, size, &ch_type);
- switch(ch_size) {
- case -1: RETURN(RC_FAIL);
- case 0: RETURN(RC_WMORE);
- default:
+ if(ch_size == -1) {
+ RETURN(RC_FAIL);
+ } else {
switch(ch_type) {
+ case PXER_WMORE:
+ RETURN(RC_WMORE);
case PXER_COMMENT: /* Got XML comment */
case PXER_TEXT: /* Ignore free-standing text */
XER_ADVANCE(ch_size); /* Skip silently */
diff --git a/skeletons/constr_SEQUENCE.c b/skeletons/constr_SEQUENCE.c
index f4785a71..a8f5cf13 100644
--- a/skeletons/constr_SEQUENCE.c
+++ b/skeletons/constr_SEQUENCE.c
@@ -692,11 +692,12 @@ SEQUENCE_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
*/
ch_size = xer_next_token(&ctx->context, buf_ptr, size,
&ch_type);
- switch(ch_size) {
- case -1: RETURN(RC_FAIL);
- case 0: RETURN(RC_WMORE);
- default:
+ if(ch_size == -1) {
+ RETURN(RC_FAIL);
+ } else {
switch(ch_type) {
+ case PXER_WMORE:
+ RETURN(RC_WMORE);
case PXER_COMMENT: /* Got XML comment */
case PXER_TEXT: /* Ignore free-standing text */
XER_ADVANCE(ch_size); /* Skip silently */
diff --git a/skeletons/constr_SET.c b/skeletons/constr_SET.c
index 1fcbc2e4..83488d90 100644
--- a/skeletons/constr_SET.c
+++ b/skeletons/constr_SET.c
@@ -675,11 +675,12 @@ SET_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
*/
ch_size = xer_next_token(&ctx->context,
buf_ptr, size, &ch_type);
- switch(ch_size) {
- case -1: RETURN(RC_FAIL);
- case 0: RETURN(RC_WMORE);
- default:
+ if(ch_size == -1) {
+ RETURN(RC_FAIL);
+ } else {
switch(ch_type) {
+ case PXER_WMORE:
+ RETURN(RC_WMORE);
case PXER_COMMENT: /* Got XML comment */
case PXER_TEXT: /* Ignore free-standing text */
XER_ADVANCE(ch_size); /* Skip silently */
diff --git a/skeletons/constr_SET_OF.c b/skeletons/constr_SET_OF.c
index b68d7ca1..e30e4a4f 100644
--- a/skeletons/constr_SET_OF.c
+++ b/skeletons/constr_SET_OF.c
@@ -549,11 +549,12 @@ SET_OF_decode_xer(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
*/
ch_size = xer_next_token(&ctx->context,
buf_ptr, size, &ch_type);
- switch(ch_size) {
- case -1: RETURN(RC_FAIL);
- case 0: RETURN(RC_WMORE);
- default:
+ if(ch_size == -1) {
+ RETURN(RC_FAIL);
+ } else {
switch(ch_type) {
+ case PXER_WMORE:
+ RETURN(RC_WMORE);
case PXER_COMMENT: /* Got XML comment */
case PXER_TEXT: /* Ignore free-standing text */
XER_ADVANCE(ch_size); /* Skip silently */
diff --git a/skeletons/tests/check-INTEGER.c b/skeletons/tests/check-INTEGER.c
index b58dd7bf..4ec9fd50 100644
--- a/skeletons/tests/check-INTEGER.c
+++ b/skeletons/tests/check-INTEGER.c
@@ -61,7 +61,7 @@ check(uint8_t *buf, int size, long check_long, int check_ret) {
assert(shared_scratch_start < scratch + sizeof(scratch));
assert(ret == 0);
ret = snprintf(verify, sizeof(verify), "%ld", check_long);
- assert(ret < sizeof(verify));
+ assert(ret < 0 || (size_t)ret < sizeof(verify));
ret = strcmp(scratch, verify);
printf(" [%s] vs [%s]: %d%s\n",
scratch, verify, ret,
@@ -170,7 +170,7 @@ check_xer(int tofail, char *xmldata, long orig_value) {
}
int
-main(int ac, char **av) {
+main() {
uint8_t buf1[] = { 1 };
uint8_t buf2[] = { 0xff };
uint8_t buf3[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
@@ -277,7 +277,7 @@ main(int ac, char **av) {
check_xer(-1, "<INTEGER>50223372036854775807</INTEGER>", 0);
check_xer(-1, "<INTEGER>100223372036854775807</INTEGER>", 0);
check_xer(-1, "<INTEGER>500223372036854775807</INTEGER>", 0);
- check_xer(0, "<INTEGER>-9223372036854775808</INTEGER>", -9223372036854775808);
+ check_xer(0, "<INTEGER>-9223372036854775808</INTEGER>", -9223372036854775807-1);
check_xer(-1, "<INTEGER>-9223372036854775809</INTEGER>", 0);
check_xer(-1, "<INTEGER>-10223372036854775807</INTEGER>", 0);
check_xer(-1, "<INTEGER>-50223372036854775807</INTEGER>", 0);
diff --git a/skeletons/tests/check-PER-INTEGER.c b/skeletons/tests/check-PER-INTEGER.c
index fc5106aa..640269b9 100644
--- a/skeletons/tests/check-PER-INTEGER.c
+++ b/skeletons/tests/check-PER-INTEGER.c
@@ -7,6 +7,9 @@
#include <per_support.h>
static int FailOut(const void *data, size_t size, void *op_key) {
+ (void)data;
+ (void)size;
+ (void)op_key;
assert(!"UNREACHABLE");
return 0;
}
@@ -89,7 +92,7 @@ check_per_encode_constrained(int lineno, int unsigned_, long value, long lbound,
recovered_value += cts.value.lower_bound;
assert((long)recovered_value == value);
}
- assert(po.nboff == ((bit_range == 32) ? 0 : (8 - (32 - bit_range))));
+ assert(po.nboff == (size_t)((bit_range == 32) ? 0 : (8 - (32 - bit_range))));
assert(po.nbits == 8 * (sizeof(po.tmpspace) - (po.buffer-po.tmpspace)));
assert(po.flushed_bytes == 0);
diff --git a/skeletons/tests/check-PER.c b/skeletons/tests/check-PER.c
index 8b55f23d..285bec07 100644
--- a/skeletons/tests/check-PER.c
+++ b/skeletons/tests/check-PER.c
@@ -178,6 +178,9 @@ check_per_decoding() {
}
static int Ignore(const void *data, size_t size, void *op_key) {
+ (void)data;
+ (void)size;
+ (void)op_key;
return 0;
}
@@ -299,7 +302,7 @@ check_per_encoding_auto() {
ASN_DEBUG("Putting %d + %d bits (%d/%d), got %d bytes and %d bits",
prior, next, (prior + next) / 8, (prior + next) % 8,
(int)(po.buffer - po.tmpspace), (int)po.nboff);
- assert((po.buffer - po.tmpspace) * 8 + po.nboff == prior + next);
+ assert((po.buffer - po.tmpspace) * 8 + po.nboff == (size_t)(prior + next));
for(i = 0; i < (po.buffer - po.tmpspace); i++)
assert(po.tmpspace[0] == (unsigned char)-1);
}
@@ -315,7 +318,6 @@ check_per_encoding_sweep_with(uint8_t buf[], int already_bits, int add_bits) {
int32_t d_add;
int32_t d_left;
int left_bits;
- int i;
memset(&pos, 0, sizeof(pos));
pos.buffer = buf;
@@ -345,10 +347,10 @@ check_per_encoding_sweep_with(uint8_t buf[], int already_bits, int add_bits) {
if(0 != memcmp(out.tmpspace, buf, buf_size)) {
printf("IN: ");
- for(i = 0; i < buf_size; i++)
+ for(size_t i = 0; i < buf_size; i++)
printf(" %02x", buf[i]);
printf("\nOUT:");
- for(i = 0; i < buf_size; i++)
+ for(size_t i = 0; i < buf_size; i++)
printf(" %02x", out.tmpspace[i]);
printf(" (out{nboff=%d,left=%d,%02x})\n", (int)out.nboff, left_bits, (int)d_left);
assert(0 == memcmp(out.tmpspace, buf, buf_size));
diff --git a/skeletons/tests/check-REAL.c b/skeletons/tests/check-REAL.c
index ba35244d..18bf8a59 100644
--- a/skeletons/tests/check-REAL.c
+++ b/skeletons/tests/check-REAL.c
@@ -22,12 +22,12 @@ callback(const void *buffer, size_t size, void *app_key) {
}
static char *
-d2s(double d, int canonical, const char *str) {
+d2s(double d, int canonical) {
ssize_t s;
reconstr_lens[canonical] = 0;
s = REAL__dump(d, canonical, callback, (void *)(ptrdiff_t)canonical);
- assert(s < sizeof(reconstructed[canonical]));
+ assert(s > 0 && (size_t)s < sizeof(reconstructed[canonical]));
assert(s == reconstr_lens[canonical]);
reconstructed[canonical][s] = '\0'; // ASCIIZ
return reconstructed[canonical];
@@ -41,8 +41,8 @@ static void
check_str_representation(double d, const char *sample, const char *canonical_sample, int lineno) {
char *s0, *s1;
- s0 = d2s(d, 0, sample);
- s1 = d2s(d, 1, canonical_sample);
+ s0 = d2s(d, 0);
+ s1 = d2s(d, 1);
if(sample) {
printf("%03d: Checking %f->[\"%s\"] against [\"%s\"]%s\n",
@@ -136,12 +136,12 @@ check_xer(int fuzzy, double orig_value) {
rc = xer_decode(0, &asn_DEF_REAL, (void **)newst0p,
reconstructed[0], reconstr_lens[0]);
assert(rc.code == RC_OK);
- assert(rc.consumed < reconstr_lens[0]);
+ assert(reconstr_lens[0] > 0 && rc.consumed < (size_t)reconstr_lens[0]);
rc = xer_decode(0, &asn_DEF_REAL, (void **)newst1p,
reconstructed[1], reconstr_lens[1]);
assert(rc.code == RC_OK);
- assert(rc.consumed == reconstr_lens[1]);
+ assert(rc.consumed == (size_t)reconstr_lens[1]);
ret = asn_REAL2double(newst0, &value0);
assert(ret == 0);
@@ -185,10 +185,10 @@ check_ber_buffer_twoway(double d, const char *sample, const char *canonical_samp
memset(&rn, 0, sizeof(rn));
ret = asn_double2REAL(&rn, d);
assert(ret == 0);
- if(rn.size != outsize) {
+ if((size_t)rn.size != outsize) {
printf("Encoded %f into %d expected %ld\n",
d, (int)rn.size, outsize);
- assert(rn.size == outsize);
+ assert((size_t)rn.size == outsize);
}
assert(memcmp(rn.buf, outbuf, rn.size) == 0);
diff --git a/skeletons/tests/check-XER.c b/skeletons/tests/check-XER.c
index 82cd0e4a..9084551c 100644
--- a/skeletons/tests/check-XER.c
+++ b/skeletons/tests/check-XER.c
@@ -31,7 +31,7 @@ check_next(char *xerbuf, int expected_chunk_size, pxer_chunk_type_e expected_chu
ch_type, (long)expected_chunk_type
);
- if(expected_chunk_type == -1) {
+ if(expected_chunk_type == PXER_WMORE) {
assert(ch_size == 0);
} else {
assert(ch_size == expected_chunk_size);
@@ -81,13 +81,13 @@ main() {
check("<tag attribute=\"value\"/>", "tag", XCT_BOTH);
check_next("<tag/>", -1, PXER_TAG);
- check_next("<tag", -1, -1);
+ check_next("<tag", -1, PXER_WMORE);
check_next("tag", -1, PXER_TEXT);
check_next("tag<s", 3, PXER_TEXT);
check_next("</a/>la", 5, PXER_TAG);
check_next("<!--blah", -1, PXER_COMMENT);
- check_next("<!--blah-", -1, -1);
- check_next("<!--blah--", -1, -1);
+ check_next("<!--blah-", -1, PXER_WMORE);
+ check_next("<!--blah--", -1, PXER_WMORE);
check_next("<!--blah-->", -1, PXER_COMMENT);
return 0;
diff --git a/skeletons/tests/check-length.c b/skeletons/tests/check-length.c
index 8c2b64b7..aa73b2c9 100644
--- a/skeletons/tests/check-length.c
+++ b/skeletons/tests/check-length.c
@@ -31,13 +31,12 @@ write_to_buf(const void *buffer, size_t size, void *key) {
static void
-check(int size) {
+check(size_t size) {
OCTET_STRING_t *os;
OCTET_STRING_t *nos = 0;
OCTET_STRING_t **nosp = &nos;
asn_enc_rval_t erval;
asn_dec_rval_t rval;
- int i;
os = OCTET_STRING_new_fromBuf(&asn_DEF_OCTET_STRING, 0, size);
assert(os);
@@ -47,14 +46,14 @@ check(int size) {
assert(os->buf);
os->size = size;
- for(i = 0; i < size; i++) {
+ for(size_t i = 0; i < size; i++) {
os->buf[i] = i;
}
buf_off = 0;
erval = der_encode(&asn_DEF_OCTET_STRING,
os, write_to_buf, 0);
- assert(erval.encoded == buf_off);
+ assert(erval.encoded >= 0 && (size_t)erval.encoded == buf_off);
assert(buf_off > size);
rval = ber_decode(0, &asn_DEF_OCTET_STRING, (void **)nosp, buf, buf_off);
@@ -63,13 +62,13 @@ check(int size) {
assert(os->size == nos->size);
- for(i = 0; i < size; i++) {
+ for(size_t i = 0; i < size; i++) {
assert(os->buf[i] == nos->buf[i]);
}
if(0) {
- fprintf(stderr, "new(%d):", size);
- for(i = 0; i < (buf_off<10?buf_off:10); i++)
+ fprintf(stderr, "new(%zd):", size);
+ for(size_t i = 0; i < (buf_off<10?buf_off:10); i++)
fprintf(stderr, " %02x", buf[i]);
printf("\n");
}
@@ -87,9 +86,8 @@ main() {
uint8_t buf4[] = { 0x89, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x04 };
ber_tlv_len_t tlv_len;
ssize_t ret;
- int i;
- for(i = 0; i < 66000; i++) {
+ for(size_t i = 0; i < 66000; i++) {
if(i == 4500) i = 64000; /* Jump */
check(i);
}
diff --git a/skeletons/xer_decoder.c b/skeletons/xer_decoder.c
index cb4b5f87..f63e1e91 100644
--- a/skeletons/xer_decoder.c
+++ b/skeletons/xer_decoder.c
@@ -70,6 +70,7 @@ xer_next_token(int *stateContext, const void *buffer, size_t size, pxer_chunk_ty
if(ret < 0) return -1;
if(arg.callback_not_invoked) {
assert(ret == 0); /* No data was consumed */
+ *ch_type = PXER_WMORE;
return 0; /* Try again with more data */
} else {
assert(arg.chunk_size);
@@ -83,7 +84,9 @@ xer_next_token(int *stateContext, const void *buffer, size_t size, pxer_chunk_ty
case PXML_TEXT:
*ch_type = PXER_TEXT;
break;
- case PXML_TAG: return 0; /* Want more */
+ case PXML_TAG:
+ *ch_type = PXER_WMORE;
+ return 0; /* Want more */
case PXML_TAG_END:
*ch_type = PXER_TAG;
break;
@@ -231,12 +234,12 @@ xer_decode_general(asn_codec_ctx_t *opt_codec_ctx,
*/
ch_size = xer_next_token(&ctx->context, buf_ptr, size,
&ch_type);
- switch(ch_size) {
- case -1: RETURN(RC_FAIL);
- case 0:
- RETURN(RC_WMORE);
- default:
+ if(ch_size == -1) {
+ RETURN(RC_FAIL);
+ } else {
switch(ch_type) {
+ case PXER_WMORE:
+ RETURN(RC_WMORE);
case PXER_COMMENT: /* Got XML comment */
ADVANCE(ch_size); /* Skip silently */
continue;
diff --git a/skeletons/xer_decoder.h b/skeletons/xer_decoder.h
index 6988648e..301b613c 100644
--- a/skeletons/xer_decoder.h
+++ b/skeletons/xer_decoder.h
@@ -60,11 +60,12 @@ asn_dec_rval_t xer_decode_general(asn_codec_ctx_t *opt_codec_ctx,
* Fetch the next XER (XML) token from the stream.
* The function returns the number of bytes occupied by the chunk type,
* returned in the _ch_type. The _ch_type is only set (and valid) when
- * the return value is greater than 0.
+ * the return value is >= 0.
*/
typedef enum pxer_chunk_type {
- PXER_TAG, /* Complete XER tag */
- PXER_TEXT, /* Plain text between XER tags */
+ PXER_WMORE, /* Chunk type is not clear, more data expected. */
+ PXER_TAG, /* Complete XER tag */
+ PXER_TEXT, /* Plain text between XER tags */
PXER_COMMENT /* A comment, may be part of */
} pxer_chunk_type_e;
ssize_t xer_next_token(int *stateContext,