Skip to content

Commit

Permalink
Fix a few Windows warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
uNetworkingAB committed Dec 26, 2019
1 parent 070d03f commit 929242c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "libusockets.h"
#include "internal/internal.h"
#include <stdlib.h>
#include <string.h>

int default_ignore_data_handler(struct us_socket_t *s) {
return 0;
Expand Down Expand Up @@ -84,8 +85,9 @@ const char *deep_str_copy(const char *src) {
if (!src) {
return src;
}
char *dst = malloc(strlen(src) + 1);
strcpy(dst, src);
size_t len = strlen(src) + 1;
char *dst = malloc(len);
memcpy(dst, src, len);
return dst;
}

Expand Down
4 changes: 2 additions & 2 deletions src/crypto/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ struct us_internal_ssl_socket_t {

int passphrase_cb(char *buf, int size, int rwflag, void *u) {
const char *passphrase = (const char *) u;
int passphrase_length = strlen(passphrase);
size_t passphrase_length = strlen(passphrase);
memcpy(buf, passphrase, passphrase_length);
// put null at end? no?
return passphrase_length;
return (int) passphrase_length;
}

int BIO_s_custom_create(BIO *bio) {
Expand Down
9 changes: 5 additions & 4 deletions src/internal/networking/bsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <WinSock2.h>
#include <Ws2tcpip.h>
#pragma comment(lib, "ws2_32.lib")
#include <stdio.h>
#define SETSOCKOPT_PTR_TYPE const char *
#define LIBUS_SOCKET_ERROR INVALID_SOCKET
#else
Expand Down Expand Up @@ -206,7 +207,7 @@ static inline LIBUS_SOCKET_DESCRIPTOR bsd_create_listen_socket(const char *host,
hints.ai_socktype = SOCK_STREAM;

char port_string[16];
sprintf(port_string, "%d", port);
snprintf(port_string, 16, "%d", port);

if (getaddrinfo(host, port_string, &hints, &result)) {
return LIBUS_SOCKET_ERROR;
Expand Down Expand Up @@ -249,7 +250,7 @@ static inline LIBUS_SOCKET_DESCRIPTOR bsd_create_listen_socket(const char *host,
setsockopt(listenFd, IPPROTO_IPV6, IPV6_V6ONLY, (SETSOCKOPT_PTR_TYPE) &disabled, sizeof(disabled));
#endif

if (bind(listenFd, listenAddr->ai_addr, listenAddr->ai_addrlen) || listen(listenFd, 512)) {
if (bind(listenFd, listenAddr->ai_addr, (socklen_t) listenAddr->ai_addrlen) || listen(listenFd, 512)) {
bsd_close_socket(listenFd);
freeaddrinfo(result);
return LIBUS_SOCKET_ERROR;
Expand All @@ -266,7 +267,7 @@ static inline LIBUS_SOCKET_DESCRIPTOR bsd_create_connect_socket(const char *host
hints.ai_socktype = SOCK_STREAM;

char port_string[16];
sprintf(port_string, "%d", port);
snprintf(port_string, 16, "%d", port);

if (getaddrinfo(host, port_string, &hints, &result) != 0) {
return LIBUS_SOCKET_ERROR;
Expand All @@ -278,7 +279,7 @@ static inline LIBUS_SOCKET_DESCRIPTOR bsd_create_connect_socket(const char *host
return LIBUS_SOCKET_ERROR;
}

connect(fd, result->ai_addr, result->ai_addrlen);
connect(fd, result->ai_addr, (socklen_t) result->ai_addrlen);
freeaddrinfo(result);

return fd;
Expand Down
2 changes: 1 addition & 1 deletion src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct us_socket_context_t *us_socket_context(int ssl, struct us_socket_t *s) {

void us_socket_timeout(int ssl, struct us_socket_t *s, unsigned int seconds) {
if (seconds) {
unsigned short timeout_sweeps = 0.5f + ((float) seconds) / ((float) LIBUS_TIMEOUT_GRANULARITY);
unsigned short timeout_sweeps = (unsigned short) (0.5f + ((float) seconds) / ((float) LIBUS_TIMEOUT_GRANULARITY));
s->timeout = timeout_sweeps ? timeout_sweeps : 1;
} else {
s->timeout = 0;
Expand Down

0 comments on commit 929242c

Please sign in to comment.