- ctx->channel_index = g_malloc(sizeof(int) * ctx->num_enabled_channels);
- ctx->channel_names = g_malloc(sizeof(char *) * ctx->num_enabled_channels);
- ctx->lines = g_malloc(sizeof(GString *) * ctx->num_enabled_channels);
- ctx->prev_sample = g_malloc(g_slist_length(o->sdi->channels));
+ ctx->channel_index = g_malloc0(sizeof(ctx->channel_index[0]) * ctx->num_enabled_channels);
+ ctx->aligned_names = g_malloc0(sizeof(ctx->aligned_names[0]) * ctx->num_enabled_channels);
+ ctx->lines = g_malloc0(sizeof(ctx->lines[0]) * ctx->num_enabled_channels);
+ ctx->prev_sample = g_malloc0(g_slist_length(o->sdi->channels));
+
+ /* Get the maximum length across all active logic channels. */
+ max_namelen = 0;
+ for (l = o->sdi->channels; l; l = l->next) {
+ ch = l->data;
+ if (ch->type != SR_CHANNEL_LOGIC)
+ continue;
+ if (!ch->enabled)
+ continue;
+ max_namelen = MAX(max_namelen, strlen(ch->name));
+ }
+ ctx->max_namelen = max_namelen;