From 6598f2012533ceff3a27023d3aee443cf3c7db5c Mon Sep 17 00:00:00 2001
From: David Wehr <dawehr@iastate.edu>
Date: Sun, 2 Apr 2017 12:33:34 -0500
Subject: [PATCH] Fixed bug with logging. Was accidentally writing rows by 4
 rather than by 1, and would write beyond the limits. Also properly
 initializing the initial value of the hw_unix_timer so Valgrind doesn't
 complain.

---
 quad/src/quad_app/log_data.c                   | 4 ++--
 quad/src/virt_quad/hw_impl_unix_global_timer.c | 3 +++
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/quad/src/quad_app/log_data.c b/quad/src/quad_app/log_data.c
index 5ca0d16a6..9448fc10d 100644
--- a/quad/src/quad_app/log_data.c
+++ b/quad/src/quad_app/log_data.c
@@ -138,7 +138,7 @@ int log_data(log_t* log_struct, parameter_t* ps)
 	{
 		return 1;
 	}
-	float* thisRow = &logArray[arrayIndex * row_size * sizeof(float)];
+	float* thisRow = &logArray[arrayIndex * row_size];
 	int offset = 0;
 	thisRow[offset++] = log_struct->time_stamp;
 	thisRow[offset++] = log_struct->gam.accel_x;
@@ -234,7 +234,7 @@ void format_log(int idx, log_t* log_struct, struct str* buf) {
 	int i;
 	buf->size = 0;
 	
-	float* row = &logArray[idx * row_size  * sizeof(float)];\
+	float* row = &logArray[idx * row_size];\
 
 	safe_sprintf_cat(buf, "%f", row[0]);
 	for (i = 1; i < row_size; i++) {
diff --git a/quad/src/virt_quad/hw_impl_unix_global_timer.c b/quad/src/virt_quad/hw_impl_unix_global_timer.c
index be752b774..dc3513d80 100644
--- a/quad/src/virt_quad/hw_impl_unix_global_timer.c
+++ b/quad/src/virt_quad/hw_impl_unix_global_timer.c
@@ -4,6 +4,9 @@ int unix_global_timer_reset(struct TimerDriver *self) {
   if (self->state == NULL) {
     self->state = malloc(sizeof(struct timeval));
   }
+  struct timezone tz;
+  struct timeval *start = self->state;
+  gettimeofday(start, &tz);
   return 0;
 }
 
-- 
GitLab