Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <cover.1764611461.git.alx@kernel.org>
Date: Mon, 1 Dec 2025 18:53:13 +0100
From: Alejandro Colomar <alx@...nel.org>
To: musl@...ts.openwall.com
Cc: Alejandro Colomar <alx@...nel.org>
Subject: [PATCH v5 0/1] include/string.h: Implement QChar and QVoid wrappers
 standardized in C23

Hi!

In v5, I've applied both suggestions from Luca Kellermann.  See
range-diff below.

Tested:

	alx@...uan:~/tmp$ cat strchr.c 
	#include <stdio.h>
	#include <string.h>

	int
	main(int argc, const char *argv[argc + 1])
	{
		char *p;


		p = strchr(argv[0], 'u');
		puts(p);

		const char *cp;

		cp = strchr(argv[0], 'u');
		puts(cp);

		&strchr(argv[0], 'u');

		strchr(argv[0], 'u') = NULL;

		int *i;

		i = strchr(i, 'u');
	}
	alx@...uan:~/tmp$ gcc -I /opt/local/musl/libc/qchar/include/ strchr.c 
	strchr.c: In function ‘main’:
	strchr.c:10:11: warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
	   10 |         p = strchr(argv[0], 'u');
	      |           ^
	strchr.c:18:9: error: lvalue required as unary ‘&’ operand
	   18 |         &strchr(argv[0], 'u');
	      |         ^
	strchr.c:20:30: error: lvalue required as left operand of assignment
	   20 |         strchr(argv[0], 'u') = NULL;
	      |                              ^
	In file included from strchr.c:2:
	strchr.c:24:20: error: passing argument 1 of ‘strchr’ from incompatible pointer type [-Wincompatible-pointer-types]
	   24 |         i = strchr(i, 'u');
	      |                    ^
	      |                    |
	      |                    int *
	/opt/local/musl/libc/qchar/include/string.h:69:54: note: in definition of macro ‘strchr’
	   69 | # define strchr(s, chr)    ((__QCharptrof(s)) strchr(s, chr))
	      |                                                      ^
	/opt/local/musl/libc/qchar/include/string.h:54:15: note: expected ‘const char *’ but argument is of type ‘int *’
	   54 | char *strchr (const char *, int);
	      |               ^~~~~~~~~~~~
	strchr.c:24:11: error: assignment to ‘int *’ from incompatible pointer type ‘char *’ [-Wincompatible-pointer-types]
	   24 |         i = strchr(i, 'u');
	      |           ^



Have a lovely night!
Alex

Alejandro Colomar (1):
  include/string.h: Implement QChar and QVoid wrappers standardized in
    C23

 include/string.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

Range-diff against v4:
1:  b891d212 ! 1:  b93da5be include/string.h: Implement QChar and QVoid wrappers standardized in C23
    @@ include/string.h: extern "C" {
      
      #include <bits/alltypes.h>
      
    -+#define __QVoidptrof(p)  typeof(1?(p):(void*)"")
    ++#define __QVoidptrof(p)  typeof(1?(p):(void*){})
     +#define __QCharptrof(s)  typeof                                       \
     +(                                                                     \
    -+	_Generic(__QVoidptrof(s),                                     \
    ++	_Generic((__QVoidptrof(s)){},                                 \
     +		const void *: (const char *) 0,                       \
     +		void *:       (char *) 0                              \
     +	)                                                             \
-- 
2.51.0

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.