Use size_t where appropriate

This commit is contained in:
akp 2023-11-11 12:20:17 +00:00
parent d105ab32c3
commit 3a4edb3fd5
2 changed files with 18 additions and 7 deletions

View file

@ -0,0 +1,11 @@
//
// Created by akp on 11/11/23.
//
#include <stdlib.h>
// Functions in this file return zero if successful or non-zero otherwise.
int handle_add_rule(char *data, size_t len) {
}

View file

@ -49,7 +49,7 @@ int open_socket(const char *ip, const char *port, int *res_sd) {
return 0;
}
int recv_n(int sd, char *buf, int n) {
int recv_n(int sd, char *buf, size_t n) {
char *buf_ptr = buf;
int num_bytes;
@ -95,9 +95,9 @@ void handle_connection(int *sdptr) {
}
char operation = leader[0];
char message_length = leader[1];
size_t message_length = leader[1];
fprintf(stderr, "[%d] Operation: %c, message length: %d\n", sd, operation, message_length);
fprintf(stderr, "[%d] Operation: %c, message length: %zu\n", sd, operation, message_length);
char *data = (char *) malloc(sizeof(char) * message_length);
@ -107,17 +107,17 @@ void handle_connection(int *sdptr) {
} else {
perror("warning: failed to receive from remote host");
}
free(data);
goto cleanup;
goto data_cleanup;
}
fprintf(stderr, "[%d] Data: %s\n", sd, data);
if (send(sd, "lmao cool\n", 10, 0) == -1) {
perror("warning: failed to send data to remote host");
goto cleanup;
goto data_cleanup;
}
data_cleanup:
free(data);
cleanup:
free(leader);