First successful run of src/decode.c

This commit is contained in:
XANTRONIX Development 2020-06-07 03:07:18 -04:00 committed by XANTRONIX Industrial
parent a8db220bbd
commit 3759469611
3 changed files with 11 additions and 6 deletions

View file

@ -12,7 +12,7 @@
#pragma pack(1)
typedef struct _patty_ax25_addr {
uint8_t callsign[6];
char callsign[6];
uint8_t ssid;
} patty_ax25_addr;

View file

@ -1,4 +1,3 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
@ -252,13 +251,13 @@ int patty_ax25_ntop(const patty_ax25_addr *addr,
goto error_invalid_args;
} else if (c == ' ' && !space) {
space = 1;
} else if (space) {
} else if (c != ' ' && space) {
errno = EINVAL;
goto error_invalid_args;
}
dest[o++] = c;
dest[o++] = space? '\0': c;
}
dest[o] = '\0';

View file

@ -19,7 +19,7 @@ static ssize_t validate_station(void *data,
if (c == ' ' && !space) {
space = 1;
} else if (space) {
} else if (c != ' ' && space) {
errno = EINVAL;
goto error;
@ -52,6 +52,8 @@ static ssize_t decode_hops(patty_ax25_frame *frame,
if ((decoded = validate_station(data, offset)) < 0) {
goto error;
} else {
memcpy(&frame->repeaters[i], addr, sizeof(*addr));
offset += decoded;
}
@ -66,7 +68,7 @@ static ssize_t decode_hops(patty_ax25_frame *frame,
* If the last hop does not have the address extension bit set, then
* that's a big problem.
*/
if (addr && PATTY_AX25_ADDRESS_OCTET_LAST(addr->ssid)) {
if (addr && !PATTY_AX25_ADDRESS_OCTET_LAST(addr->ssid)) {
errno = EINVAL;
goto error;
@ -87,12 +89,16 @@ static ssize_t decode_address(patty_ax25_frame *frame,
if ((decoded = validate_station(data, offset)) < 0) {
goto error;
} else {
memcpy(&frame->dest, ((uint8_t *)data) + offset, sizeof(frame->dest));
offset += decoded;
}
if ((decoded = validate_station(data, offset)) < 0) {
goto error;
} else {
memcpy(&frame->src, ((uint8_t *)data) + offset, sizeof(frame->src));
offset += decoded;
}