diff --git a/dse/clib/data/marshal.c b/dse/clib/data/marshal.c index c3823d0..543b16e 100644 --- a/dse/clib/data/marshal.c +++ b/dse/clib/data/marshal.c @@ -546,10 +546,10 @@ void marshal_signalmap_out(MarshalSignalMap* map) src_binary[src_idx] = NULL; } src_binary_len[src_idx] = 0; - if (sig_binary_len[sig_idx] && sig_binary_len[sig_idx]) { + if (sig_binary[sig_idx] && sig_binary_len[sig_idx]) { src_binary[src_idx] = malloc(sig_binary_len[sig_idx]); src_binary_len[src_idx] = sig_binary_len[sig_idx]; - memcpy(src_binary[src_idx], sig_binary[src_idx], + memcpy(src_binary[src_idx], sig_binary[sig_idx], sig_binary_len[sig_idx]); } log_trace(" signal[%d]->source[%d]: (%p:%d)->(%p:%d)", sig_idx, diff --git a/tests/data/test_marshal.c b/tests/data/test_marshal.c index d3e9b67..3296cd3 100644 --- a/tests/data/test_marshal.c +++ b/tests/data/test_marshal.c @@ -930,6 +930,20 @@ void test_marshal__signalmap_binary_out(void** state) strdup("bar") }, .binary.expected.binary_len = { 4, 6, 4 }, }, + { + // One signal is NULL but len is set (incorrectly). + .name = "foo", + .count = 2, + .signal_idx = { 0, 1 }, + .source_idx = { 0, 1 }, + .binary.signal.binary = { NULL, strdup("bar") }, + .binary.signal.binary_len = { 4, 4 }, + .binary.signal.binary_buffer_size = { 4, 4 }, + .binary.source.binary = { NULL, NULL }, + .binary.source.binary_len = { 0, 0 }, + .binary.expected.binary = { NULL, strdup("bar") }, + .binary.expected.binary_len = { 0, 4 }, + }, }; /* Check every test case. */ @@ -957,10 +971,14 @@ void test_marshal__signalmap_binary_out(void** state) for (size_t j = 0; j < msm[0].count; j++) { assert_int_equal(tc[i].binary.expected.binary_len[j], msm[0].source.binary_len[j]); - assert_ptr_not_equal(tc[i].binary.signal.binary[j], - tc[i].binary.source.binary[j]); - assert_memory_equal(tc[i].binary.expected.binary[j], - msm[0].source.binary[j], tc[i].binary.expected.binary_len[j]); + if (tc[i].binary.expected.binary[j]) { + assert_ptr_not_equal(tc[i].binary.signal.binary[j], + tc[i].binary.source.binary[j]); + assert_memory_equal(tc[i].binary.expected.binary[j], + msm[0].source.binary[j], tc[i].binary.expected.binary_len[j]); + } else { + assert_null(tc[i].binary.signal.binary[j]); + } } /* Cleanup. */