~adnano/wmenu-devel

Fix build failure when compiling in release v1 APPLIED

Piotr Stefański: 1
 Fix build failure when compiling in release

 1 files changed, 1 insertions(+), 1 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~adnano/wmenu-devel/patches/46095/mbox | git am -3
Learn more about email & git

[PATCH] Fix build failure when compiling in release Export this patch

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.
---

Build output:
[1/2] Compiling C object wmenu.p/main.c.o
FAILED: wmenu.p/main.c.o
cc -Iwmenu.p -I. -I.. -Iprotocols -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/freetype2 -I/usr/include/libpng16 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/fribidi -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Werror -std=c11 -O3 '-DVERSION="0.1.4"' -Wno-missing-field-initializers -Wno-unused-parameter -Wundef -Wvla -pthread -MD -MQ wmenu.p/main.c.o -MF wmenu.p/main.c.o.d -o wmenu.p/main.c.o -c ../main.c
In function ‘insert’,
    inlined from ‘keypress’ at ../main.c:556:4:
../main.c:935:17: error: argument 2 null where non-null expected [-Werror=nonnull]
  935 |                 memcpy(state->text + state->cursor, s, n);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from ../main.c:11:
/usr/include/string.h: In function ‘keypress’:
/usr/include/string.h:43:14: note: in a call to function ‘memcpy’ declared ‘nonnull’
   43 | extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
      |              ^~~~~~
In function ‘insert’,
    inlined from ‘keypress’ at ../main.c:562:5:
../main.c:935:17: error: argument 2 null where non-null expected [-Werror=nonnull]
  935 |                 memcpy(state->text + state->cursor, s, n);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/string.h: In function ‘keypress’:
/usr/include/string.h:43:14: note: in a call to function ‘memcpy’ declared ‘nonnull’
   43 | extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
      |              ^~~~~~
In function ‘insert’,
    inlined from ‘keypress’ at ../main.c:565:5:
../main.c:935:17: error: argument 2 null where non-null expected [-Werror=nonnull]
  935 |                 memcpy(state->text + state->cursor, s, n);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/string.h: In function ‘keypress’:
/usr/include/string.h:43:14: note: in a call to function ‘memcpy’ declared ‘nonnull’
   43 | extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
      |              ^~~~~~
In function ‘insert’,
    inlined from ‘keypress’ at ../main.c:772:4:
../main.c:935:17: error: argument 2 null where non-null expected [-Werror=nonnull]
  935 |                 memcpy(state->text + state->cursor, s, n);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/string.h: In function ‘keypress’:
/usr/include/string.h:43:14: note: in a call to function ‘memcpy’ declared ‘nonnull’
   43 | extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
      |              ^~~~~~
In function ‘insert’,
    inlined from ‘keypress’ at ../main.c:782:3:
../main.c:935:17: error: argument 2 null where non-null expected [-Werror=nonnull]
  935 |                 memcpy(state->text + state->cursor, s, n);
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/string.h: In function ‘keypress’:
/usr/include/string.h:43:14: note: in a call to function ‘memcpy’ declared ‘nonnull’
   43 | extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
      |              ^~~~~~
cc1: all warnings being treated as errors
ninja: build stopped: subcommand failed.


 main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/main.c b/main.c
index 9291119..056e0a3 100644
--- a/main.c
+++ b/main.c
@@ -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;
-- 
2.39.2
Thanks!

To git@git.sr.ht:~adnano/wmenu
   2b9e08f..dacae03  master -> master

I couldn't reproduce the GCC error, but this change looks correct to me.