-
Notifications
You must be signed in to change notification settings - Fork 56
Open
Description
Hello,
I noticed that handle_char uses a static buffer to buffer words, which sounds like it could cause issues when running two instances on two different threads:
static void handle_char(zf_ctx *ctx, char c)
{
// Static buffer, shared between threads.
static char buf[32];
static size_t len = 0;
if(ctx->input_state == ZF_INPUT_PASS_CHAR) {
ctx->input_state = ZF_INPUT_INTERPRET;
run(ctx, &c);
} else if(c != '\0' && !isspace(c)) {
if(len < sizeof(buf)-1) {
// Buffer access, not synchronized.
buf[len++] = c;
buf[len] = '\0';
}
} else {
if(len > 0) {
len = 0;
handle_word(ctx, buf);
}
}
}I can't test if this actually breaks in the real world right now, but this sounds like a potential race condition under true parallelism?
Best,
Philipp
Metadata
Metadata
Assignees
Labels
No labels