Skip to content

Commit

Permalink
Fix compiler warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
hurufu committed Apr 23, 2024
1 parent ba08279 commit 0e9b521
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 24 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ CPPFLAGS_clang := -D_FORTIFY_SOURCE=3
# Some gcc builds (depends on the distro) set _FORTIFY_SOURCE by default,
# so we need undefine it and then redefine it
CPPFLAGS_gcc := -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -D_GLIBCXX_ASSERTIONS
CPPFLAGS_cc = $(CPPFLAGS_gcc)
CPPFLAGS ?= $(CPPFLAGS_$(CC))
CPPFLAGS += -I$(PROJECT_DIR) -I$(PROJECT_DIR)/multitasking
#CPPFLAGS += -DNDEBUG
Expand All @@ -21,6 +22,7 @@ CFLAGS_gcc := -fanalyzer -fanalyzer-checker=taint -fsanitize=bounds -fsanitize-u
CFLAGS_gcc += -Wformat -Werror=format-security -grecord-gcc-switches
CFLAGS_gcc += -fstack-protector-all
CFLAGS_gcc += -fstack-clash-protection
CFLAGS_cc = $(CFLAGS_gcc)
CFLAGS ?= -std=gnu11 -O$(OPTLEVEL) -ggdb3 -Wall -Wextra -flto $(CFLAGS_$(CC))
CFLAGS += $(call if_coverage,--coverage)
#CFLAGS += -fstrict-flex-arrays
Expand All @@ -35,7 +37,7 @@ LDFLAGS += $(call if_coverage,--coverage)
# Project configuration ########################################################
RL_C := wireprotocol.c frontend.c
RL_O := $(RL_C:.c=.o)
CFILES := main.c log.c utils.c serialization.c
CFILES := main.c log.c utils.c serialization.c autoresponder.c
OFILES := $(RL_O) $(CFILES:.c=.o)
UT_C := ut.c serialization.c log.c utils.c contextring.c
UT_O := $(UT_C:.c=.o) header.o body.o frame.o attrs.o
Expand Down Expand Up @@ -67,7 +69,7 @@ clang-analyze: $(ALL_PLIST)
tcp-server: frob | d5.txt
s6-tcpserver -vd -b2 0.0.0.0 5002 s6-tcpserver-access -t200 -v3 -rp -B "Welcome!\r\n" $(realpath $<) 1000 $|
tcp-client: frob | d5.txt
s6-tcpclient -rv localhost 5002 rlwrap $(realpath $<) 1000 $|
s6-tcpclient -rv localhost 5002 rlwrap $(realpath $<) 1000 $| 2>&1 | s6-tai64n | s6-tai64nlocal
tls-server: frob server.cer server.key | d5.txt
env -i PATH=/bin CERTFILE=$(word 2,$^) KEYFILE=$(word 3,$^) s6-tlsserver 0.0.0.0 6666 $(realpath $<) -f $(word 1,$^)
tls-client: frob server.cer | d5.txt
Expand Down
16 changes: 16 additions & 0 deletions autoresponder.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "frob.h"
#include "log.h"
#include "utils.h"
#include "multitasking/sus.h"

int autoresponder(void*) {
ssize_t bytes;
const char* p;
while ((bytes = sus_borrow(1, (void**)&p)) >= 0) {
unsigned char t2[] = "1T2T";
sus_write(6, t2, sizeof t2);
LOGDXP(char tmp[4*sizeof t2], "← % 4zd %s", sizeof t2, PRETTY(t2, t2 + sizeof t2, tmp));
sus_return(1, p, bytes);
}
return -1;
}
7 changes: 6 additions & 1 deletion frob.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,14 @@ struct fsm_frontend_timer_args {
int cs;
};

struct fsm_wireformat_args {};
struct fsm_wireformat_args {
const int infd;
};

struct autoresponder_args {};

int fsm_wireformat(void*);
int fsm_frontend_foreign(struct fsm_frontend_foreign_args*);
int fsm_frontend_internal(struct fsm_frontend_internal_args*);
int fsm_frontend_timer(struct fsm_frontend_timer_args*);
int autoresponder(void*);
6 changes: 3 additions & 3 deletions fsm/frontend.rl
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ static int cs;
LOGE("write");
fbreak;
}
LOGDXP(char tmp[4*1], "← % 4zd %s", 1, PRETTY(&acknak, &acknak + 1, tmp));
LOGDXP(char tmp[4*1], "← % 4d %s", 1, PRETTY(&acknak, &acknak + 1, tmp));
}
action Process {
sus_lend(1, pe - p, p);
sus_lend(1, pe - p, (char*)p);// TODO: Remove this cast
}

foreign = OK @Confirm @Send @Process | NAK @Reject @Send;
Expand All @@ -61,7 +61,7 @@ static bool is_idempotent(const char* const msg) {
*/

static int fsm_exec(const char* p, const char* const pe) {
char acknak;
unsigned char acknak;
%% write exec;
return -1;
}
Expand Down
13 changes: 0 additions & 13 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,6 @@ static void test_all_channels(const int (* const fd)[CHANNEL_COUNT]) {
LOGE("Channel %s (fd %d) is unusable", channel_to_string(i), (*fd)[i]);
}

struct autoresponder_args {};

int autoresponder(void*) {
ssize_t bytes;
const char* p;
while ((bytes = sus_borrow(1, (void**)&p)) >= 0) {
char t2[] = "1T2T";
sus_write(6, t2, sizeof t2);
LOGDXP(char tmp[4*sizeof t2], "← % 4zd %s", sizeof t2, PRETTY(t2, t2 + sizeof t2, tmp));
sus_return(1, p, bytes);
}
}

int main() {
init_log();
int fds[CHANNEL_COUNT] = {
Expand Down
11 changes: 6 additions & 5 deletions multitasking/suspendables.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "contextring.h"
#include "eventloop.h"
#include "../log.h"
#include "../utils.h"
#include <assert.h>
#include <string.h>
#include <unistd.h>
Expand Down Expand Up @@ -181,7 +182,7 @@ int sus_ioloop(struct sus_ioloop_args* const args) {
.maxfd = 10,
.deadline = comp_deadline(args->timeout)
};
int ret;
int ret = 0;
do {
again:
if (s_current == s_current->next) {
Expand Down Expand Up @@ -209,8 +210,8 @@ int sus_ioloop(struct sus_ioloop_args* const args) {
LOGE("iowait failed");
else if (ret == 0)
LOGI("iowait done");
close(0);
close(1);
for (int i = 0; i < 10; i++)
close(i);
LOGDX("surrended");
s_io_surrended = true;
return -1;
Expand All @@ -233,9 +234,9 @@ int sus_runall(const size_t length, struct sus_registation_form (* const h)[leng
ret = 0;
end:
for (size_t i = 0; i < length; i++) {
coro_destroy(&stuff[i].ctx);
(void)coro_destroy(&stuff[i].ctx);
coro_stack_free(&stuff[i].stack);
}
coro_destroy(&s_end);
(void)coro_destroy(&s_end);
return ret;
}

0 comments on commit 0e9b521

Please sign in to comment.