Commit 53e5ae65 authored by Lev Walkin's avatar Lev Walkin

honor contract wrt zero-termination

parent 8c060139
...@@ -512,13 +512,13 @@ asn_REAL2double(const REAL_t *st, double *dbl_value) { ...@@ -512,13 +512,13 @@ asn_REAL2double(const REAL_t *st, double *dbl_value) {
} }
/* 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(). * OCTET STRING decoder ensures that, as is asn_double2REAL().
* 2. ISO 6093 specifies COMMA as a possible decimal separator. * 2. ISO 6093 specifies COMMA as a possible decimal separator.
* However, strtod() can't always deal with COMMA. * However, strtod() can't always deal with COMMA.
* So her we fix both by reallocating, copying and fixing. * 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; uint8_t *p, *end;
char *b; char *b;
if(st->size > 100) { if(st->size > 100) {
......
...@@ -167,7 +167,7 @@ check_xer(int fuzzy, double orig_value) { ...@@ -167,7 +167,7 @@ check_xer(int fuzzy, double orig_value) {
} }
static void 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; REAL_t rn;
double val; double val;
int ret; int ret;
...@@ -175,7 +175,9 @@ check_ber_buffer_twoway(double d, const char *sample, const char *canonical_samp ...@@ -175,7 +175,9 @@ check_ber_buffer_twoway(double d, const char *sample, const char *canonical_samp
/* /*
* Decode our expected buffer and check that it matches the given (d). * 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; rn.size = insize;
asn_REAL2double(&rn, &val); asn_REAL2double(&rn, &val);
if(isnan(val)) assert(isnan(d)); if(isnan(val)) assert(isnan(d));
...@@ -188,6 +190,7 @@ check_ber_buffer_twoway(double d, const char *sample, const char *canonical_samp ...@@ -188,6 +190,7 @@ check_ber_buffer_twoway(double d, const char *sample, const char *canonical_samp
/* /*
* Encode value and check that it matches our expected buffer. * Encode value and check that it matches our expected buffer.
*/ */
free(rn.buf);
memset(&rn, 0, sizeof(rn)); memset(&rn, 0, sizeof(rn));
ret = asn_double2REAL(&rn, d); ret = asn_double2REAL(&rn, d);
assert(ret == 0); assert(ret == 0);
......
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