Skip to content

Commit

Permalink
mqtt_pal: Fix pointer arithmetic to not use compiler extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
learn-more committed Oct 2, 2020
1 parent 1c4245e commit 9666ecc
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/mqtt_pal.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ ssize_t mqtt_pal_recvall(mqtt_pal_socket_handle fd, void* buf, size_t bufsz, int
ssize_t mqtt_pal_sendall(mqtt_pal_socket_handle fd, const void* buf, size_t len, int flags) {
size_t sent = 0;
while(sent < len) {
int tmp = BIO_write(fd, buf + sent, len - sent);
int tmp = BIO_write(fd, (const char*)buf + sent, len - sent);
if (tmp > 0) {
sent += (size_t) tmp;
} else if (tmp <= 0 && !BIO_should_retry(fd)) {
Expand All @@ -235,21 +235,22 @@ ssize_t mqtt_pal_sendall(mqtt_pal_socket_handle fd, const void* buf, size_t len,
}

ssize_t mqtt_pal_recvall(mqtt_pal_socket_handle fd, void* buf, size_t bufsz, int flags) {
const void *const start = buf;
const char* const start = buf;
char* bufptr = buf;
int rv;
do {
rv = BIO_read(fd, buf, bufsz);
rv = BIO_read(fd, bufptr, bufsz);
if (rv > 0) {
/* successfully read bytes from the socket */
buf += rv;
bufptr += rv;
bufsz -= rv;
} else if (!BIO_should_retry(fd)) {
/* an error occurred that wasn't "nothing to read". */
return MQTT_ERROR_SOCKET_ERROR;
}
} while (!BIO_should_read(fd));

return (ssize_t)(buf - start);
return (ssize_t)(bufptr - start);
}

#elif defined(__unix__) || defined(__APPLE__)
Expand Down

0 comments on commit 9666ecc

Please sign in to comment.