From 3d5729f7b704c49b50956ae81568cccb56d366ac Mon Sep 17 00:00:00 2001 From: marcsello Date: Fri, 6 Nov 2020 02:44:09 +0100 Subject: [PATCH] Changed error codes --- src/caff_tools.c | 2 +- src/caff_tools.h | 27 +++++++++++++++------------ src/ciff_tools.h | 14 ++++++++------ src/pixeldata_utils.c | 2 +- src/pixeldata_utils.h | 7 +++++-- src/utils.h | 12 +++++++----- 6 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/caff_tools.c b/src/caff_tools.c index deda807..4f9318a 100644 --- a/src/caff_tools.c +++ b/src/caff_tools.c @@ -193,5 +193,5 @@ uint8_t parse_caff_get_first_ciff(uint8_t *caff_data, uint64_t caff_data_len, ui p += seek_by; } - return CAFF_PARSE_ANIMATION_COUNT_ERROR; + return CAFF_PARSE_UNKNOWN_ERROR; } \ No newline at end of file diff --git a/src/caff_tools.h b/src/caff_tools.h index 9ab43dd..b19fb45 100644 --- a/src/caff_tools.h +++ b/src/caff_tools.h @@ -7,19 +7,22 @@ #include -#define CAFF_PARSE_SUCCESS 0 -#define CAFF_PARSE_LENGTH_ERROR 1 -#define CAFF_PARSE_BAD_FRAME 2 -#define CAFF_PARSE_HEADER_ERROR 3 -#define CAFF_PARSE_ANIMATION_COUNT_ERROR 4 -#define CAFF_PARSE_NO_CREDITS_ERROR 5 -#define CAFF_PARSE_BAD_MAGIC 6 -#define CAFF_PARSE_BAD_DATE 7 -#define CAFF_PARSE_NO_DURATION 8 +#define CAFF_PARSE_ERROR_PREFIX 0x10 +#define CAFF_PARSE_LENGTH_ERROR (CAFF_PARSE_ERROR_PREFIX + 0x01) +#define CAFF_PARSE_BAD_FRAME (CAFF_PARSE_ERROR_PREFIX + 0x02) +#define CAFF_PARSE_HEADER_ERROR (CAFF_PARSE_ERROR_PREFIX + 0x03) +#define CAFF_PARSE_ANIMATION_COUNT_ERROR (CAFF_PARSE_ERROR_PREFIX + 0x04) +#define CAFF_PARSE_NO_CREDITS_ERROR (CAFF_PARSE_ERROR_PREFIX + 0x05) +#define CAFF_PARSE_BAD_MAGIC (CAFF_PARSE_ERROR_PREFIX + 0x06) +#define CAFF_PARSE_BAD_DATE (CAFF_PARSE_ERROR_PREFIX + 0x07) +#define CAFF_PARSE_NO_DURATION (CAFF_PARSE_ERROR_PREFIX + 0x08) +#define CAFF_PARSE_UNKNOWN_ERROR (CAFF_PARSE_ERROR_PREFIX + 0x09) -#define CAFF_FRAME_HEADER 0x1 -#define CAFF_FRAME_CREDITS 0x2 -#define CAFF_FRAME_ANIMATION 0x3 +#define CAFF_PARSE_SUCCESS 0x00 + +#define CAFF_FRAME_HEADER 0x1 +#define CAFF_FRAME_CREDITS 0x2 +#define CAFF_FRAME_ANIMATION 0x3 diff --git a/src/ciff_tools.h b/src/ciff_tools.h index 08b6cbe..5a87a11 100644 --- a/src/ciff_tools.h +++ b/src/ciff_tools.h @@ -7,12 +7,14 @@ #include -#define CIFF_PARSE_UNKNOWN_ERROR 1 -#define CIFF_PARSE_HEADER_LENGTHS_INCORRECT 2 -#define CIFF_PARSE_HEADER_DIMENSIONS_INCORRECT 3 -#define CIFF_PARSE_HEADER_TOO_SHORT 4 -#define CIFF_PARSE_HEADER_BAD_MAGIC 5 -#define CIFF_PARSE_SUCCESS 0 +#define CIFF_PARSE_ERROR_PREFIX 0x20 +#define CIFF_PARSE_HEADER_LENGTHS_INCORRECT (CIFF_PARSE_ERROR_PREFIX + 0x01) +#define CIFF_PARSE_HEADER_DIMENSIONS_INCORRECT (CIFF_PARSE_ERROR_PREFIX + 0x02) +#define CIFF_PARSE_HEADER_TOO_SHORT (CIFF_PARSE_ERROR_PREFIX + 0x03) +#define CIFF_PARSE_HEADER_BAD_MAGIC (CIFF_PARSE_ERROR_PREFIX + 0x04) +#define CIFF_PARSE_UNKNOWN_ERROR (CIFF_PARSE_ERROR_PREFIX + 0x05) + +#define CIFF_PARSE_SUCCESS 0x00 typedef struct __attribute__ ((packed)) ciff_static_header_t { uint32_t magic; // should be equal to 0x46464943 (Because x86 is big-endian, so essentially this is in reverse) diff --git a/src/pixeldata_utils.c b/src/pixeldata_utils.c index 4860739..531cb94 100644 --- a/src/pixeldata_utils.c +++ b/src/pixeldata_utils.c @@ -7,7 +7,7 @@ uint8_t flip_image(const uint8_t *source, uint8_t *destination, uint64_t data_length, uint64_t width, uint64_t height) { if ((width*height*3) != data_length) { - return IMAGE_FLIP_FAIL; + return IMAGE_FLIP_LENGTH_ERROR; } for (uint64_t i = 0; i < height; i++) { diff --git a/src/pixeldata_utils.h b/src/pixeldata_utils.h index 04ca1de..921df94 100644 --- a/src/pixeldata_utils.h +++ b/src/pixeldata_utils.h @@ -7,8 +7,11 @@ #include -#define IMAGE_FLIP_SUCCESS 0 -#define IMAGE_FLIP_FAIL 0 + +#define IMAGE_FLIP_ERROR_PREFIX 0x30 +#define IMAGE_FLIP_LENGTH_ERROR (IMAGE_FLIP_ERROR_PREFIX + 0x01) + +#define IMAGE_FLIP_SUCCESS 0x00 uint8_t flip_image(const uint8_t* source, uint8_t* destination, uint64_t data_length, uint64_t width, uint64_t height); diff --git a/src/utils.h b/src/utils.h index 0b335d1..779a99b 100644 --- a/src/utils.h +++ b/src/utils.h @@ -10,11 +10,13 @@ #include "magic_memory.h" -#define FILE_READ_COULD_NOT_OPEN 1 -#define FILE_READ_TOO_BIG 2 -#define FILE_READ_COULD_NOT_ALLOCATE 3 -#define FILE_READ_ERROR 4 -#define FILE_READ_SUCCESS 0 +#define FILE_READ_ERROR_PREFIX 0x00 +#define FILE_READ_COULD_NOT_OPEN (FILE_READ_ERROR_PREFIX + 0x01) +#define FILE_READ_TOO_BIG (FILE_READ_ERROR_PREFIX + 0x02) +#define FILE_READ_COULD_NOT_ALLOCATE (FILE_READ_ERROR_PREFIX + 0x03) +#define FILE_READ_ERROR (FILE_READ_ERROR_PREFIX + 0x04) + +#define FILE_READ_SUCCESS 0x00 bool contains(const uint8_t *data, uint64_t data_len, uint8_t what);