From: Wolfram Sang Date: Thu, 11 May 2017 11:51:08 +0000 (+0200) Subject: output/csv: fix segfault with logic channels X-Git-Tag: libsigrok-0.5.0~68 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=d3cc09a612a6f8f2bf258bbd33a7dfd2c3a30968;p=libsigrok.git output/csv: fix segfault with logic channels 'i' was iterating in steps of unitsize. However, the destination array was also indexed with it, but it is of u8 type. Let 'i' run bytewise and only multiply with unitsize when we need it. This fixes parts of bug #844. Signed-off-by: Wolfram Sang --- diff --git a/src/output/csv.c b/src/output/csv.c index 97102f45..f3e6e335 100644 --- a/src/output/csv.c +++ b/src/output/csv.c @@ -378,8 +378,8 @@ static void process_logic(struct context *ctx, for (j = ch = 0; ch < ctx->num_logic_channels; j++) { if (ctx->channels[j].ch->type == SR_CHANNEL_LOGIC) { - for (i = 0; i <= logic->length - logic->unitsize; i += logic->unitsize) { - sample = logic->data + i; + for (i = 0; i < num_samples; i++) { + sample = logic->data + i * logic->unitsize; idx = ctx->channels[ch].ch->index; if (ctx->label_do && !ctx->label_names) ctx->channels[j].label = "logic";