From 502814f50a12fa124c8e1b22b249a0f0e8ec6156 Mon Sep 17 00:00:00 2001 From: Sani7 Date: Sat, 4 Nov 2023 20:28:34 +0100 Subject: [PATCH] safe array Move structs back to header file --- src/safe_array.c | 39 +++------------------------------------ src/safe_array.h | 33 +++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 40 deletions(-) diff --git a/src/safe_array.c b/src/safe_array.c index c036687..bf28a73 100644 --- a/src/safe_array.c +++ b/src/safe_array.c @@ -10,11 +10,7 @@ * * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -//#include "safe_array.h" -#include -#include -#include -#include +#include "safe_array.h" /** * @brief This function generates a safe array @@ -24,35 +20,6 @@ * @return array_t* The pointer to the safe array struct */ -typedef struct array_s -{ - size_t rows; - size_t size; - uint8_t data[1]; -} array_t; - -typedef struct array_2d_s -{ - size_t rows; - size_t cols; - size_t size; - uint8_t data[1]; -} array_2d_t; - -typedef struct array_c_s -{ - size_t rows; - size_t size; - uint8_t data[2]; -} array_c_s_t; - -typedef struct array_c_p_s -{ - size_t rows; - size_t size; - uint8_t data[2]; -} array_c_p_t; - array_t *array_init(size_t size, size_t rows) { array_t *arr = calloc(sizeof(array_t) + (size * rows - 1), 1); @@ -281,7 +248,7 @@ void array_2d_free(array_2d_t *x) */ array_c_s_t *array_c_s_init(size_t rows, size_t size) { - array_c_s_t *x = calloc(sizeof(array_c_s_t) + (2 * rows * size) - 2, 1); + array_c_s_t *x = calloc(sizeof(array_c_s_t) + (2 * rows * size) - 1, 1); if (!x) { fprintf(stderr, "%s: Failed to allocate memory for array", __func__); @@ -392,7 +359,7 @@ void array_c_s_free(array_c_s_t *x) */ array_c_p_t *array_c_p_init(size_t rows, size_t size) { - array_c_p_t* x = calloc(sizeof(array_c_p_t) + (2 * rows * size) - 2, 1); + array_c_p_t* x = calloc(sizeof(array_c_p_t) + (2 * rows * size) - 1, 1); if (!x) { fprintf(stderr, "%s: Failed to allocate memory for array", __func__); diff --git a/src/safe_array.h b/src/safe_array.h index 665a945..7168b30 100644 --- a/src/safe_array.h +++ b/src/safe_array.h @@ -23,10 +23,35 @@ #define ARRAY_C_GET_MAG(arr, row, type) (*(type *)array_c_get_mag(arr, row)) #define ARRAY_C_GET_PHASE(arr, row, type) (*(type *)array_c_get_phase(arr, row)) -typedef void array_t; -typedef void array_2d_t; -typedef void array_c_s_t; -typedef void array_c_p_t; + +typedef struct array_s +{ + size_t rows; + size_t size; + uint8_t data[1]; +} array_t; + +typedef struct array_2d_s +{ + size_t rows; + size_t cols; + size_t size; + uint8_t data[1]; +} array_2d_t; + +typedef struct array_c_s +{ + size_t rows; + size_t size; + uint8_t data[1]; +} array_c_s_t; + +typedef struct array_c_p_s +{ + size_t rows; + size_t size; + uint8_t data[1]; +} array_c_p_t; // Array.c array_t *array_init(size_t size, size_t rows);