From 2ea4739bbda35e5d886b2a60006ef66b397b6d00 Mon Sep 17 00:00:00 2001
From: Yifan Zhao <yifanz16@illinois.edu>
Date: Thu, 23 Jan 2020 17:56:01 -0600
Subject: [PATCH] Fixed bug in cava

---
 hpvm/test/hpvm-cava/src/cam_pipe_utility.c | 16 ++++++++++------
 hpvm/test/hpvm-cava/src/cam_pipe_utility.h |  7 ++++---
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/hpvm/test/hpvm-cava/src/cam_pipe_utility.c b/hpvm/test/hpvm-cava/src/cam_pipe_utility.c
index 864f02d5b2..4ef58c3bcb 100644
--- a/hpvm/test/hpvm-cava/src/cam_pipe_utility.c
+++ b/hpvm/test/hpvm-cava/src/cam_pipe_utility.c
@@ -5,29 +5,33 @@
 #include "cam_pipe_utility.h"
 //#include "pipe_stages.h"
 
-uint8_t *read_image_from_binary(char *file_path, int *row_size, int *col_size) {
+uint8_t *read_image_from_binary(char *file_path, size_t *row_size,
+                                size_t *col_size) {
   uint8_t *image;
   FILE *fp = fopen(file_path, "r");
   int chan_size;
-  if (fread(row_size, sizeof(int), 1, fp) != 1)
+  int row_size_tmp, col_size_tmp;
+  if (fread(&row_size_tmp, sizeof(int), 1, fp) != 1)
     assert("Failed to read row size from binary file!");
-  if (fread(col_size, sizeof(int), 1, fp) != 1)
+  if (fread(&col_size_tmp, sizeof(int), 1, fp) != 1)
     assert("Failed to read col size from binary file!");
   if (fread(&chan_size, sizeof(int), 1, fp) != 1)
     assert("Failed to read row size from binary file!");
   assert(chan_size == CHAN_SIZE && "Channel size read from the binary file "
                                    "doesn't equal to the default value!\n");
 
-  int size = *row_size * *col_size * CHAN_SIZE;
+  size_t size = (size_t)row_size_tmp * col_size_tmp * CHAN_SIZE;
   image = malloc_aligned(sizeof(uint8_t) * size);
   if (fread(image, sizeof(uint8_t), size, fp) != size)
     assert("Failed to read the image from binary file!");
   fclose(fp);
+  *row_size = (size_t)row_size_tmp;
+  *col_size = (size_t)col_size_tmp;
   return image;
 }
 
-void write_image_to_binary(char *file_path, uint8_t *image, int row_size,
-                           int col_size) {
+void write_image_to_binary(char *file_path, uint8_t *image, size_t row_size,
+                           size_t col_size) {
   FILE *fp = fopen(file_path, "w");
 
   int shape[3] = {row_size, col_size, CHAN_SIZE};
diff --git a/hpvm/test/hpvm-cava/src/cam_pipe_utility.h b/hpvm/test/hpvm-cava/src/cam_pipe_utility.h
index b61b7cc9b5..a7ba68372a 100644
--- a/hpvm/test/hpvm-cava/src/cam_pipe_utility.h
+++ b/hpvm/test/hpvm-cava/src/cam_pipe_utility.h
@@ -4,9 +4,10 @@
 #include "pipe_stages.h"
 #include "utility.h"
 
-uint8_t *read_image_from_binary(char *file_path, int *row_size, int *col_size);
-void write_image_to_binary(char *file_path, uint8_t *image, int row_size,
-                           int col_size);
+uint8_t *read_image_from_binary(char *file_path, size_t *row_size,
+                                size_t *col_size);
+void write_image_to_binary(char *file_path, uint8_t *image, size_t row_size,
+                           size_t col_size);
 float *transpose_mat(float *inmat, int width, int height);
 void convert_hwc_to_chw(uint8_t *input, int row_size, int col_size,
                         uint8_t **result);
-- 
GitLab