Skip to content

Commit

Permalink
change the send_string function, to accept null pointers and send them
Browse files Browse the repository at this point in the history
as empty strings.
  • Loading branch information
jtsiomb committed Apr 26, 2022
1 parent 92481cc commit 1716ccf
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/proto.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ int spnav_send_str(int fd, int req, const char *str)
int len;
struct reqresp rr = {0};

if(fd == -1 || !str) {
if(fd == -1) {
return -1;
}

len = strlen(str);
len = str ? strlen(str) : 0;
rr.type = req;
rr.data[6] = len;

do {
memcpy(rr.data, str, len > REQSTR_CHUNK_SIZE ? REQSTR_CHUNK_SIZE : len);
if(str) {
memcpy(rr.data, str, len > REQSTR_CHUNK_SIZE ? REQSTR_CHUNK_SIZE : len);
}
write(fd, &rr, sizeof rr);
str += REQSTR_CHUNK_SIZE;
len -= REQSTR_CHUNK_SIZE;
Expand Down

0 comments on commit 1716ccf

Please sign in to comment.