ham64: apply improvements suggested by rudi_s

This commit is contained in:
Simon Ruderich 2024-07-04 21:09:09 +02:00 committed by Thomas Kolb
parent 212da1f78e
commit ee5c62167a

View file

@ -51,7 +51,7 @@ size_t ham64_encode(const char *call, ham64_t *ham64)
uint16_t *tmp = ham64->addr; uint16_t *tmp = ham64->addr;
memset(ham64->addr, 0, 4*sizeof(uint16_t)); memset(ham64->addr, 0, sizeof(ham64->addr));
while(*call) { while(*call) {
uint16_t encoded = char_to_ham64(*call); uint16_t encoded = char_to_ham64(*call);
@ -137,7 +137,8 @@ const char *ham64_addr_type_to_string(ham64_addr_type_t addr_type)
"BROADCAST", "BROADCAST",
"IPV6_MULTICAST", "IPV6_MULTICAST",
"IPV4_MULTICAST", "IPV4_MULTICAST",
"RESERVED"}; "RESERVED",
};
if(addr_type >= HAM64_NUM_ADDR_TYPES) { if(addr_type >= HAM64_NUM_ADDR_TYPES) {
return NULL; return NULL;
@ -173,7 +174,8 @@ ham64_addr_type_t ham64_get_addr_type(const ham64_t *ham64)
void ham64_format(const ham64_t *ham64, char *out) void ham64_format(const ham64_t *ham64, char *out)
{ {
for(uint8_t i = 0; i < ham64->length; i++) { for(uint8_t i = 0; i < ham64->length; i++) {
sprintf(out + 5 * i, "%04X-", ham64->addr[i]); const char *fmt = (i == 3) ? "%04X" : "%04X-";
sprintf(out + 5 * i, fmt, ham64->addr[i]);
} }
out[5*ham64->length - 1] = '\0'; out[5*ham64->length - 1] = '\0';