From 4db2a65b23b63aa504b20523dd155364aad30e93 Mon Sep 17 00:00:00 2001 From: Anders Blomdell <anders.blomdell@control.lth.se> Date: Mon, 25 May 2015 23:32:19 +0200 Subject: [PATCH] Fixed return of reference to possibly moving memory. --- lib/c/2014/labcomm2014_decoder.c | 25 +++++++++++++---------- lib/c/2014/labcomm2014_renaming_decoder.c | 4 ++-- test/Makefile | 6 ++++-- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/lib/c/2014/labcomm2014_decoder.c b/lib/c/2014/labcomm2014_decoder.c index 4935e4d..b1cfcd8 100644 --- a/lib/c/2014/labcomm2014_decoder.c +++ b/lib/c/2014/labcomm2014_decoder.c @@ -265,23 +265,26 @@ out: } static labcomm2014_decoder_function lookup_h(struct labcomm2014_decoder *d, - struct call_handler_context *wrap, - int remote_index, - int **local_index) + struct call_handler_context *wrap, + int remote_index, + int *r_local_index) { struct decoder *id = d->context; labcomm2014_decoder_function do_decode = NULL; + int *local_index; + labcomm2014_scheduler_data_lock(d->scheduler); - *local_index = LABCOMM_SIGNATURE_ARRAY_REF(d->memory, - id->remote_to_local, int, - remote_index); - if (**local_index != 0) { + local_index = LABCOMM_SIGNATURE_ARRAY_REF(d->memory, + id->remote_to_local, int, + remote_index); + *r_local_index = *local_index; + if (*local_index != 0) { struct sample_entry *entry; entry = LABCOMM_SIGNATURE_ARRAY_REF(d->memory, id->local, struct sample_entry, - **local_index); - wrap->local_index = **local_index; + *local_index); + wrap->local_index = *local_index; wrap->signature = entry->signature; wrap->handler = entry->handler; wrap->context = entry->context; @@ -300,7 +303,7 @@ static int decode_and_handle(struct labcomm2014_decoder *d, int remote_index) { int result; - int *local_index; + int local_index; struct call_handler_context wrap = { .reader = d->reader, .remote_index = remote_index, @@ -309,7 +312,7 @@ static int decode_and_handle(struct labcomm2014_decoder *d, .context = NULL, }; labcomm2014_decoder_function do_decode = lookup_h(registry, &wrap, remote_index, &local_index); - result = *local_index; + result = local_index; if (do_decode) { do_decode(d->reader, call_handler, &wrap); if (d->reader->error < 0) { diff --git a/lib/c/2014/labcomm2014_renaming_decoder.c b/lib/c/2014/labcomm2014_renaming_decoder.c index 4243438..88cdb76 100644 --- a/lib/c/2014/labcomm2014_renaming_decoder.c +++ b/lib/c/2014/labcomm2014_renaming_decoder.c @@ -168,8 +168,8 @@ static const struct labcomm2014_sample_ref *do_ref_get( { const struct labcomm2014_signature *renamed; struct decoder *id = d->context; - - renamed = get_renamed(d, signature); + + renamed = get_renamed(d, signature); if (renamed == NULL) { return id->next->ref_get(id->next, signature); } else { diff --git a/test/Makefile b/test/Makefile index 456cc4e..0714905 100644 --- a/test/Makefile +++ b/test/Makefile @@ -1,4 +1,6 @@ -TESTS=basic simple nested ref +TESTS_RENAME=basic simple nested # sample_ref's does not transfer between + # encoder decoder for now +TESTS=$(TESTS_RENAME) ref LABCOMM_JAR=../compiler/labcomm2014_compiler.jar LABCOMM=java -jar $(LABCOMM_JAR) MONO_PATH=$(shell pwd)/../lib/csharp @@ -8,7 +10,7 @@ include ../lib/c/os_compat.mk all: -test: $(TESTS:%=test_%) $(TESTS:%=test_renaming_%) compiler_errors +test: $(TESTS:%=test_%) $(TESTS_RENAME:%=test_renaming_%) compiler_errors # PYTHONPATH=../lib/python \ # ./test_encoder_decoder.py --labcomm="$(LABCOMM)" basic.lc -- GitLab