honor contract wrt zero-termination
diff --git a/skeletons/REAL.c b/skeletons/REAL.c
index ce03522..c510db5 100644
--- a/skeletons/REAL.c
+++ b/skeletons/REAL.c
@@ -512,13 +512,13 @@
}
- /* 1. By contract, an input buffer should be null-terminated.
+ /* 1. By contract, an input buffer should be '\0'-terminated.
* OCTET STRING decoder ensures that, as is asn_double2REAL().
* 2. ISO 6093 specifies COMMA as a possible decimal separator.
* However, strtod() can't always deal with COMMA.
* So her we fix both by reallocating, copying and fixing.
*/
- if(st->buf[st->size] || memchr(st->buf, ',', st->size)) {
+ if(st->buf[st->size] != '\0' || memchr(st->buf, ',', st->size)) {
uint8_t *p, *end;
char *b;
if(st->size > 100) {
diff --git a/skeletons/tests/check-REAL.c b/skeletons/tests/check-REAL.c
index 4251c8a..9e32c40 100644
--- a/skeletons/tests/check-REAL.c
+++ b/skeletons/tests/check-REAL.c
@@ -167,7 +167,7 @@
}
static void
-check_ber_buffer_twoway(double d, const char *sample, const char *canonical_sample, uint8_t *inbuf, size_t insize, uint8_t *outbuf, size_t outsize, int lineno) {
+check_ber_buffer_twoway(double d, const char *sample, const char *canonical_sample, const uint8_t *inbuf, size_t insize, uint8_t *outbuf, size_t outsize, int lineno) {
REAL_t rn;
double val;
int ret;
@@ -175,7 +175,9 @@
/*
* Decode our expected buffer and check that it matches the given (d).
*/
- rn.buf = inbuf;
+ rn.buf = calloc(1, insize + 1); /* By convention, buffers have extra \0 */
+ assert(rn.buf);
+ memcpy(rn.buf, inbuf, insize);
rn.size = insize;
asn_REAL2double(&rn, &val);
if(isnan(val)) assert(isnan(d));
@@ -188,6 +190,7 @@
/*
* Encode value and check that it matches our expected buffer.
*/
+ free(rn.buf);
memset(&rn, 0, sizeof(rn));
ret = asn_double2REAL(&rn, d);
assert(ret == 0);