Only need one of those memcpy() around
This commit is contained in:
parent
3759469611
commit
0decdda086
1 changed files with 8 additions and 11 deletions
19
src/frame.c
19
src/frame.c
|
@ -3,8 +3,9 @@
|
|||
|
||||
#include <patty/ax25.h>
|
||||
|
||||
static ssize_t validate_station(void *data,
|
||||
off_t offset) {
|
||||
static ssize_t decode_station(patty_ax25_addr *addr,
|
||||
void *data,
|
||||
off_t offset) {
|
||||
int i, space = 0;
|
||||
|
||||
for (i=0; i<PATTY_AX25_CALLSIGN_LEN; i++) {
|
||||
|
@ -26,6 +27,8 @@ static ssize_t validate_station(void *data,
|
|||
}
|
||||
}
|
||||
|
||||
memcpy(addr, ((uint8_t *)data) + offset, sizeof(*addr));
|
||||
|
||||
return PATTY_AX25_ADDRESS_SIZE;
|
||||
|
||||
error:
|
||||
|
@ -49,11 +52,9 @@ static ssize_t decode_hops(patty_ax25_frame *frame,
|
|||
for (i=0; i<PATTY_AX25_MAX_HOPS; i++) {
|
||||
addr = (patty_ax25_addr *)((uint8_t *)data + offset);
|
||||
|
||||
if ((decoded = validate_station(data, offset)) < 0) {
|
||||
if ((decoded = decode_station(&frame->repeaters[i], data, offset)) < 0) {
|
||||
goto error;
|
||||
} else {
|
||||
memcpy(&frame->repeaters[i], addr, sizeof(*addr));
|
||||
|
||||
offset += decoded;
|
||||
}
|
||||
|
||||
|
@ -86,19 +87,15 @@ static ssize_t decode_address(patty_ax25_frame *frame,
|
|||
off_t offset = start;
|
||||
ssize_t decoded;
|
||||
|
||||
if ((decoded = validate_station(data, offset)) < 0) {
|
||||
if ((decoded = decode_station(&frame->dest, 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) {
|
||||
if ((decoded = decode_station(&frame->src, data, offset)) < 0) {
|
||||
goto error;
|
||||
} else {
|
||||
memcpy(&frame->src, ((uint8_t *)data) + offset, sizeof(frame->src));
|
||||
|
||||
offset += decoded;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue