forked from github/abduco
Use more appropriate types
This commit is contained in:
parent
42bcd723bd
commit
fcaf5368fa
10
abduco.c
10
abduco.c
|
|
@ -80,7 +80,7 @@ typedef struct {
|
|||
/* packet sent from server to all clients */
|
||||
typedef struct {
|
||||
char buf[BUFSIZ];
|
||||
ssize_t len;
|
||||
size_t len;
|
||||
} ServerPacket;
|
||||
|
||||
typedef struct {
|
||||
|
|
@ -116,9 +116,9 @@ typedef struct {
|
|||
ServerPacket pty_output;
|
||||
ClientPacketState pty_input;
|
||||
ClientPacket queue[10];
|
||||
int queue_count;
|
||||
int queue_insert;
|
||||
int queue_remove;
|
||||
unsigned int queue_count;
|
||||
unsigned int queue_insert;
|
||||
unsigned int queue_remove;
|
||||
int pty;
|
||||
int exit_status;
|
||||
struct termios term;
|
||||
|
|
@ -184,7 +184,7 @@ static int create_socket_dir() {
|
|||
if (!dir)
|
||||
dir = "/tmp";
|
||||
int len = snprintf(sockaddr.sun_path, maxlen, "%s/.%s/", dir, server.name);
|
||||
if (len >= maxlen)
|
||||
if (len < 0 || (size_t)len >= maxlen)
|
||||
return -1;
|
||||
if (mkdir(sockaddr.sun_path, 0750) == -1 && errno != EEXIST)
|
||||
return -1;
|
||||
|
|
|
|||
8
client.c
8
client.c
|
|
@ -7,7 +7,7 @@ static void client_sigwinch_handler(int sig) {
|
|||
static ssize_t write_all(int fd, const char *buf, size_t len) {
|
||||
ssize_t ret = len;
|
||||
while (len > 0) {
|
||||
int res = write(fd, buf, len);
|
||||
ssize_t res = write(fd, buf, len);
|
||||
if (res < 0) {
|
||||
if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
|
||||
continue;
|
||||
|
|
@ -24,7 +24,7 @@ static ssize_t write_all(int fd, const char *buf, size_t len) {
|
|||
static ssize_t read_all(int fd, char *buf, size_t len) {
|
||||
ssize_t ret = len;
|
||||
while (len > 0) {
|
||||
int res = read(fd, buf, len);
|
||||
ssize_t res = read(fd, buf, len);
|
||||
if (res < 0) {
|
||||
if (errno == EWOULDBLOCK)
|
||||
return ret - len;
|
||||
|
|
@ -51,9 +51,9 @@ static bool client_send_packet(ClientPacket *pkt) {
|
|||
}
|
||||
|
||||
static bool client_recv_packet(ServerPacket *pkt) {
|
||||
pkt->len = read_all(server.socket, pkt->buf, sizeof(pkt->buf));
|
||||
ssize_t len = pkt->len = read_all(server.socket, pkt->buf, sizeof(pkt->buf));
|
||||
print_server_packet("client-recv:", pkt);
|
||||
if (pkt->len <= 0) {
|
||||
if (len <= 0) {
|
||||
debug("FAILED\n");
|
||||
server.running = false;
|
||||
return false;
|
||||
|
|
|
|||
2
debug.c
2
debug.c
|
|
@ -35,7 +35,7 @@ static void print_client_packet(const char *prefix, ClientPacket *pkt) {
|
|||
|
||||
if (pkt->type == MSG_CONTENT) {
|
||||
fprintf(stderr, "%s %s len: %d content: ", prefix, s, pkt->len);
|
||||
for (int i = 0; i < pkt->len && i < sizeof(pkt->u.msg); i++)
|
||||
for (size_t i = 0; i < pkt->len && i < sizeof(pkt->u.msg); i++)
|
||||
fprintf(stderr, "%c", pkt->u.msg[i]);
|
||||
fprintf(stderr, "\n");
|
||||
} else {
|
||||
|
|
|
|||
4
server.c
4
server.c
|
|
@ -74,7 +74,7 @@ static bool server_recv_packet(Client *c) {
|
|||
ClientPacketState *pkt = &c->input;
|
||||
if (is_client_packet_complete(pkt))
|
||||
return true;
|
||||
int count = sizeof(ClientPacket) - pkt->off;
|
||||
size_t count = sizeof(ClientPacket) - pkt->off;
|
||||
ssize_t len = recv(c->socket, ((char *)&pkt->pkt) + pkt->off, count, 0);
|
||||
switch (len) {
|
||||
case -1:
|
||||
|
|
@ -95,7 +95,7 @@ static bool server_send_packet(Client *c) {
|
|||
ServerPacketState *pkt = &c->output;
|
||||
if (is_server_packet_complete(pkt))
|
||||
return true;
|
||||
int count = pkt->pkt->len - pkt->off;
|
||||
size_t count = pkt->pkt->len - pkt->off;
|
||||
ssize_t len = send(c->socket, pkt->pkt->buf + pkt->off, count, 0);
|
||||
switch (len) {
|
||||
case -1:
|
||||
|
|
|
|||
Loading…
Reference in New Issue