Fix build failure when compiling in release

Compiling with --buildtype=release fails with message:

../main.c:935:17: error: argument 2 null where non-null expected [-Werror=nonnull]
  935 |                 memcpy(state->text + state->cursor, s, n);

GCC only produces this error with optimizations enabled. Looking at
the build output I assume this happens because it tries to inline the
function.
This commit is contained in:
Piotr Stefański 2023-10-26 20:34:17 +02:00 committed by adnano
parent adf5cda6e1
commit e120b9156e

2
main.c
View file

@ -931,7 +931,7 @@ void insert(struct menu_state *state, const char *s, ssize_t n) {
}
memmove(state->text + state->cursor + n, state->text + state->cursor,
sizeof state->text - state->cursor - MAX(n, 0));
if (n > 0) {
if (n > 0 && s != NULL) {
memcpy(state->text + state->cursor, s, n);
}
state->cursor += n;