[lib-result] mobile_mac_addr as static buffer

The mobile_mac_addr field of the struct _owl_result is now a static char
buffer instead of being dynamically-allocated. When reading the MAC
address, it is also more thoroughly verified.
This commit is contained in:
Matteo Cypriani 2013-09-25 11:28:30 -04:00
parent 5d71ca9ae2
commit 669f5b1064
2 changed files with 14 additions and 7 deletions

View File

@ -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) ;
}

View File

@ -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 ;