From: Bert Vermeulen Date: Wed, 29 Dec 2010 00:22:58 +0000 (+0100) Subject: proper fix for output_text corner cases X-Git-Tag: libsigrok-0.1.0~477 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=339729131d5acd50147e26ec238db569e273a459;p=libsigrok.git proper fix for output_text corner cases limit probe names to 32 chars --- diff --git a/output/output_text.c b/output/output_text.c index f6d9357a..621729b7 100644 --- a/output/output_text.c +++ b/output/output_text.c @@ -69,6 +69,7 @@ static void flush_linebufs(struct context *ctx, char *outbuf) ctx->mark_trigger + (ctx->mark_trigger / 8), ""); memset(ctx->linebuf, 0, i * ctx->linebuf_len); + } static int init(struct output *o, int default_spl) @@ -180,12 +181,13 @@ static int data_bits(struct output *o, char *data_in, uint64_t length_in, { struct context *ctx; unsigned int outsize, offset, p; + int max_linelen; uint64_t sample; char *outbuf; ctx = o->internal; - outsize = length_in / ctx->unitsize * ctx->num_enabled_probes * - ctx->samples_per_line + 4096; + max_linelen = MAX_PROBENAME_LEN + 3 + ctx->samples_per_line + ctx->samples_per_line / 8; + outsize = length_in / ctx->unitsize * ctx->num_enabled_probes / ctx->samples_per_line * max_linelen + 512; if (!(outbuf = calloc(1, outsize + 1))) return SIGROK_ERR_MALLOC; @@ -248,12 +250,13 @@ static int data_hex(struct output *o, char *data_in, uint64_t length_in, { struct context *ctx; unsigned int outsize, offset, p; + int max_linelen; uint64_t sample; char *outbuf; ctx = o->internal; - outsize = length_in / ctx->unitsize * ctx->num_enabled_probes * - ctx->samples_per_line + 4096; + max_linelen = MAX_PROBENAME_LEN + 3 + ctx->samples_per_line + ctx->samples_per_line / 2; + outsize = length_in / ctx->unitsize * ctx->num_enabled_probes / ctx->samples_per_line * max_linelen + 512; if (!(outbuf = calloc(1, outsize + 1))) return SIGROK_ERR_MALLOC; diff --git a/sigrok.h b/sigrok.h index a1531bf7..b34d2b41 100644 --- a/sigrok.h +++ b/sigrok.h @@ -210,6 +210,7 @@ struct device { struct datastore *datastore; }; +#define MAX_PROBENAME_LEN 32 struct probe { int index; gboolean enabled;