Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 03 Aug 2023 11:48:34 +0000
From:      bugzilla-noreply@freebsd.org
To:        standards@FreeBSD.org
Subject:   [Bug 272914] wcscmp is not ISO C compliant
Message-ID:  <bug-272914-99@https.bugs.freebsd.org/bugzilla/>

next in thread | raw e-mail | index | archive | help
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D272914

            Bug ID: 272914
           Summary: wcscmp is not ISO C compliant
           Product: Base System
           Version: 13.2-RELEASE
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: standards
          Assignee: standards@FreeBSD.org
          Reporter: bruno@clisp.org

ISO C 23 =C2=A7 7.31.4.4.1 together with =C2=A7 7.31.4.4.(1) and =C2=A7 7.3=
1.1.(6) specifies
that wcscmp must compare the string elements as wchar_t values, and that all
wchar_t values can legitimately occur.

On FreeBSD/x86_64, wchar_t is signed, i.e. equivalent to 'int'. In the test
case below, cmp must therefore come out positive, since a[0] > 0 > b[0]. But
wcscmp in FreeBSD compares the wchar_t values as if they were unsigned.

How to reproduce:
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D foo.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
#include <wchar.h>
int main ()
{
  /* This test fails on glibc < 2.15, musl libc 1.2.3, macOS 12.5,
     FreeBSD 13.2, NetBSD 9.0, OpenBSD 7.2, Solaris 11.4.  */
  wchar_t a[2] =3D { (wchar_t) 0x76547654, 0 };
  wchar_t b[2] =3D { (wchar_t) 0x9abc9abc, 0 };
  int cmp =3D wcscmp (a, b);
  return (!((wchar_t)-1 < 0 ? cmp > 0 : cmp < 0));
}
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
$ cc foo.c
$ ./a.out
$ echo $?
1

--=20
You are receiving this mail because:
You are the assignee for the bug.=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-272914-99>