diff --git a/libowlps-resultreader/libowlps-resultreader.c b/libowlps-resultreader/libowlps-resultreader.c index 61813bb..64d8fba 100644 --- a/libowlps-resultreader/libowlps-resultreader.c +++ b/libowlps-resultreader/libowlps-resultreader.c @@ -110,8 +110,16 @@ owl_result* owl_fill_result(char *csv) " string (empty string?)!\n") ; goto error ; } - result->mobile_mac_addr = - strndup(csv_field, OWL_ETHER_ADDR_STRLEN) ; + if (strnlen(csv_field, OWL_ETHER_ADDR_STRLEN) + != OWL_ETHER_ADDR_STRLEN - 1) + { + csv_field[OWL_ETHER_ADDR_STRLEN-1] = '\0' ; + fprintf(stderr, + "The string \"%s\" is not a valid MAC address!\n", + csv_field) ; + goto error ; + } + strncpy(result->mobile_mac_addr, csv_field, OWL_ETHER_ADDR_STRLEN) ; /* Request type */ if (! owl_read_long_field(&csv, CSV_DELIMITER, &longfield)) @@ -528,9 +536,9 @@ void owl_fprint_algorithm_result(FILE *stream, /** - * Frees the memory allocated for an `owl_result`. The `results` and - * `mobile_mac_addr` fields of `result` *must* be defined, either to - * `NULL` or to a valid memory block allocated with `malloc()`. + * Frees the memory allocated for an `owl_result`. The `results` field + * of `result` *must* be defined, either to `NULL` or to a valid memory + * block allocated with `malloc()`. * Note that `result` will not be set to `NULL`. */ void owl_free_result(owl_result *const result) @@ -543,7 +551,6 @@ void owl_free_result(owl_result *const result) result->results = algo->next ; owl_free_algorithm_result(algo) ; } - free(result->mobile_mac_addr) ; free(result) ; } diff --git a/libowlps-resultreader/owlps-resultreader.h b/libowlps-resultreader/owlps-resultreader.h index 05edca1..601cb38 100644 --- a/libowlps-resultreader/owlps-resultreader.h +++ b/libowlps-resultreader/owlps-resultreader.h @@ -96,7 +96,7 @@ typedef struct _owl_algorithm_result owl_algorithm_result ; */ struct _owl_result { - char *mobile_mac_addr ; ///< Mobile's MAC address + char mobile_mac_addr[OWL_ETHER_ADDR_STRLEN] ; ///< Mobile's MAC address uint8_t request_type ; ///< Type of the request /// Local time on the mobile when sending the request owl_timestamp mobile_timestamp ;