diff options
| author | Thorsten Töpper <atsutane@freethoughts.de> | 2025-08-14 21:34:19 +0200 |
|---|---|---|
| committer | Thorsten Töpper <atsutane@freethoughts.de> | 2025-08-14 21:34:19 +0200 |
| commit | 23d2f670808933aa20448194b2a4ff26386d7905 (patch) | |
| tree | 2cd04179c3f4118738a630ef460a45e93a21fcba | |
| parent | 5667b14ca2e4fa3637ec9e13f8e2ea05eeef47dc (diff) | |
| download | small-utils-23d2f670808933aa20448194b2a4ff26386d7905.tar.gz small-utils-23d2f670808933aa20448194b2a4ff26386d7905.tar.bz2 | |
tree_based_check: switch to unsigned values
| -rw-r--r-- | include/hex_conversion.h | 14 | ||||
| -rw-r--r-- | src/tree_based_check.c | 24 |
2 files changed, 20 insertions, 18 deletions
diff --git a/include/hex_conversion.h b/include/hex_conversion.h index 4b97d6d..e232b8e 100644 --- a/include/hex_conversion.h +++ b/include/hex_conversion.h @@ -15,9 +15,9 @@ #define ishex_macro(c) ((c>='0' && c <= '9') || (c>='A' && c <= 'F') || (c>='a' && c <= 'f')) int convert_line(char *s); -int ishex(char c); -char *convert_to_binary(char *hex, char *out); -char *convert_from_binary(char *bin, size_t l, char *out); +int ishex(unsigned char c); +unsigned char *convert_to_binary(char *hex, unsigned char *out); +char *convert_from_binary(unsigned char *bin, size_t l, char *out); /* short inline functions are fine in header */ inline int convert_line(char *s) { @@ -35,14 +35,14 @@ inline int convert_line(char *s) { return 0; } -inline int ishex(char c) { +inline int ishex(unsigned char c) { if ((c>='0' && c <= '9') || (c>='A' && c <= 'F') || (c>='a' && c <= 'f')) { return 1; } return 0; }; -inline char *convert_to_binary(char *hex, char *out) { +inline unsigned char *convert_to_binary(char *hex, unsigned char *out) { char tmp[3] = {0,0,0}; size_t length, i; if (hex == NULL) return NULL; @@ -65,14 +65,14 @@ inline char *convert_to_binary(char *hex, char *out) { for (i=0;i<length;i+=2) { tmp[0] = hex[i]; tmp[1] = hex[i+1]; - out[i/2] = (char) strtol(tmp, NULL, 16); + out[i/2] = (unsigned char) strtol(tmp, NULL, 16); } return out; } /* Use a large buffer and complex method, as with a simple * way there regularly were corrupt results with gcc -O2. */ -inline char *convert_from_binary(char *bin, size_t l, char *out) { +inline char *convert_from_binary(unsigned char *bin, size_t l, char *out) { char tmp[24]; size_t i,pos; if (bin == NULL || l == 0) return NULL; diff --git a/src/tree_based_check.c b/src/tree_based_check.c index abf1232..6e76981 100644 --- a/src/tree_based_check.c +++ b/src/tree_based_check.c @@ -36,7 +36,7 @@ struct list_node { struct list_node *next; - char data[FULL_DATABLOCK_SIZE]; + unsigned char data[FULL_DATABLOCK_SIZE]; }; struct list_head { @@ -64,14 +64,14 @@ size_t freed = 0; struct list_head *create_list_head(); void destroy_list(struct list_head *head); -int insert_data_into_list(struct list_head *head, char *data); +int insert_data_into_list(struct list_head *head, unsigned char *data); int remove_data_from_list(struct list_head *head, char *data); -int check_list_for_data(struct list_head *head, char *data); +int check_list_for_data(struct list_head *head, unsigned char *data); struct tree_root *create_tree_root(); void destroy_tree_branches(struct tree_branch *branch); void destroy_tree(struct tree_root *root); -int insert_into_tree(struct tree_root *root, char *data); -int check_tree_for_data(struct tree_root *root, char *data); +int insert_into_tree(struct tree_root *root, unsigned char *data); +int check_tree_for_data(struct tree_root *root, unsigned char *data); void print_list_plain(struct list_head *head, FILE *fd); void print_tree_branch(struct tree_branch *branch, FILE *fd); void print_tree(struct tree_root *root, FILE *fd); @@ -135,7 +135,7 @@ inline void destroy_list(struct list_head *head) { } /* No time consuming duplicate check, data to be processed is expected to be gone sorted through uniq */ -inline int insert_data_into_list(struct list_head *head, char *data) { +inline int insert_data_into_list(struct list_head *head, unsigned char *data) { struct list_node *node; if (head == NULL || data == NULL) { LOGERR("ERROR: Improper arguments.\n"); @@ -217,7 +217,7 @@ inline int remove_data_from_list(struct list_head *head, char *data) { * removed to safe time with future checks. However, in case the input file is * sorted, Thread safety has negative performance impact. */ -inline int check_list_for_data(struct list_head *head, char *data) { +inline int check_list_for_data(struct list_head *head, unsigned char *data) { struct list_node *node; int rc = 1; if (head == NULL || data == NULL) { @@ -275,7 +275,7 @@ inline void destroy_tree(struct tree_root *root) { free(root); } -inline int insert_into_tree(struct tree_root *root, char *data) { +inline int insert_into_tree(struct tree_root *root, unsigned char *data) { int depth = 0, i =0; struct tree_branch *ptr = NULL; unsigned char uc = 0; @@ -323,7 +323,7 @@ inline int insert_into_tree(struct tree_root *root, char *data) { /* Return values: * < 0 ERROR | == 0 FOUND | > 0 NOT FOUND */ -inline int check_tree_for_data(struct tree_root *root, char *data) { +inline int check_tree_for_data(struct tree_root *root, unsigned char *data) { int depth = 0; struct tree_branch *ptr; unsigned char uc; @@ -391,7 +391,8 @@ struct tree_root *read_file_into_tree(char *filename) { size_t line_nr=0; struct tree_root *root = NULL; FILE *fd = NULL; - char *line = NULL, *data = NULL; + char *line = NULL; + unsigned char *data = NULL; if (filename == NULL || strlen(filename) == 0) { return NULL; @@ -461,7 +462,8 @@ struct tree_root *read_file_into_tree(char *filename) { int filter_file_with_tree(char *filename, FILE *output, struct tree_root *root) { size_t line_nr=0; FILE *fd = NULL; - char *line = NULL, *data = NULL; + char *line = NULL; + unsigned char *data = NULL; int check_result = 0; int rc = 0; |
