From: Martin Ling Date: Fri, 26 Apr 2013 20:35:18 +0000 (+0100) Subject: ascii: fix for big-endian architectures. X-Git-Tag: dsupstream~51 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=3a581560f1288b4cecc4ab885c85ac7603dd21db;p=libsigrok.git ascii: fix for big-endian architectures. --- diff --git a/output/text/ascii.c b/output/text/ascii.c index ab3c7f12..f93e3b81 100644 --- a/output/text/ascii.c +++ b/output/text/ascii.c @@ -46,7 +46,7 @@ SR_PRIV int data_ascii(struct sr_output *o, const uint8_t *data_in, struct context *ctx; unsigned int outsize, offset, p; int max_linelen; - uint64_t sample; + const uint8_t *sample; uint8_t *outbuf; ctx = o->internal; @@ -75,14 +75,14 @@ SR_PRIV int data_ascii(struct sr_output *o, const uint8_t *data_in, if (length_in >= ctx->unitsize) { for (offset = 0; offset <= length_in - ctx->unitsize; offset += ctx->unitsize) { - memcpy(&sample, data_in + offset, ctx->unitsize); + sample = data_in + offset; char tmpval[ctx->num_enabled_probes]; for (p = 0; p < ctx->num_enabled_probes; p++) { - uint64_t curbit = (sample & ((uint64_t) 1 << p)); - uint64_t prevbit = (ctx->prevsample & - ((uint64_t) 1 << p)); + uint8_t curbit = (sample[p / 8] & ((uint8_t) 1 << (p % 8))); + uint8_t prevbit = (ctx->prevsample[p / 8] & + ((uint8_t) 1 << (p % 8))); if (curbit < prevbit && ctx->line_offset > 0) { ctx->linebuf[p * ctx->linebuf_len + @@ -114,7 +114,7 @@ SR_PRIV int data_ascii(struct sr_output *o, const uint8_t *data_in, ctx->line_offset++; ctx->spl_cnt++; - ctx->prevsample = sample; + memcpy(ctx->prevsample, sample, ctx->unitsize); } } else { sr_info("Short buffer (length_in=%" PRIu64 ").", length_in); diff --git a/output/text/text.c b/output/text/text.c index 30e04696..674fa886 100644 --- a/output/text/text.c +++ b/output/text/text.c @@ -154,6 +154,12 @@ SR_PRIV int init(struct sr_output *o, int default_spl, enum outputmode mode) ret = SR_ERR_MALLOC; } + if (mode == MODE_ASCII && + !(ctx->prevsample = g_try_malloc0(num_probes / 8))) { + sr_err("%s: ctx->prevsample malloc failed", __func__); + ret = SR_ERR_MALLOC; + } + err: if (ret != SR_OK) { g_free(ctx->header); diff --git a/output/text/text.h b/output/text/text.h index 78ef4783..f3ada90d 100644 --- a/output/text/text.h +++ b/output/text/text.h @@ -42,7 +42,7 @@ struct context { uint8_t *linevalues; char *header; int mark_trigger; - uint64_t prevsample; + uint8_t *prevsample; enum outputmode mode; };