On Mon, Aug 18, 2025 at 07:23:38PM +0200, Otto Moerbeek wrote:
> On Mon, Aug 18, 2025 at 06:40:04PM +0200, Walter Alejandro Iglesias wrote:
> 
> > Question for the experts.  Let's take the following example:
> > 
> > ----->8------------->8--------------------
> > #include <stdio.h>
> > #include <string.h>
> > #include <wchar.h>
> > 
> > #define period              0x2e
> > #define question    0x3f
> > #define exclam              0x21
> > #define ellipsis    L'\u2026'
> > 
> > const wchar_t p[] = { period, question, exclam, ellipsis };
> 
> This is not a string, as is is not NUL terminated, so there's garbage
> after it, which will be picked up by wcsspn() until it hits a NUL.

If you look at the asm output from the compiler using -S:

$ cc -S prog.c
$ view prog.s

... you'll likely see that what follows the const definition of p[] in memory
is actually s[], so you're basically feeding both p[] and s[] as the charset
argument to wcsspan().

Reply via email to