fix wcwidth to work with gcc 16 sign extension (Re: wchar.h: tweak wcwidth prototype parameter wchar_t -> wint_t)
| Message ID | 49097df7-bf9a-4710-8e5a-74765d839791@towo.net |
|---|---|
| State | New |
| Headers |
Return-Path: <newlib-bounces~patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E3D4E4BA2E23 for <patchwork@sourceware.org>; Wed, 3 Jun 2026 00:43:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E3D4E4BA2E23 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=towo.net header.i=towo@towo.net header.a=rsa-sha256 header.s=s1-ionos header.b=HZ8u4OUn X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.17.10]) by sourceware.org (Postfix) with ESMTPS id ADC774BA2E06 for <newlib@sourceware.org>; Wed, 3 Jun 2026 00:43:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org ADC774BA2E06 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=towo.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=towo.net ARC-Filter: OpenARC Filter v1.0.0 sourceware.org ADC774BA2E06 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=212.227.17.10 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780447390; cv=none; b=O4TeuHw2dID1R0KUN9Z5FRu6xfo/mt8Dc2q4SyBKlQ571dY6jRmkqELWZZvjzZqY/m59hPMMR+9axxGwc4f6NVgrjmjgTyWIUKQjdlNsO3JfQTEy8NYFD5dc7CPK6JEo8adU1wN8NbwUc7qO+uOjD8PWajHyUYnSbQ9QZVqj4YM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780447390; c=relaxed/simple; bh=/p0T6bhAfOUBi15Xj9k5VsFeXw52dTERIPVGaGB4/tk=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=MI9hXI2z8VXDcFStvp5Jw9Ucu5aJssC9/GfAHJrdHj9a5g/I580TpPZKRwH0NUasV7UfmNpWb54nRZEy25Osw1h43e00WMtaC45z0PZwugF3R6lvV9UrY1fwGi7vhpViBaSXlmMXU2iuU/p5Hd9IRT+fp6tvfNTq03bT6arLlHo= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=towo.net header.i=towo@towo.net header.a=rsa-sha256 header.s=s1-ionos header.b=HZ8u4OUn DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ADC774BA2E06 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=towo.net; s=s1-ionos; t=1780447388; x=1781052188; i=towo@towo.net; bh=/p0T6bhAfOUBi15Xj9k5VsFeXw52dTERIPVGaGB4/tk=; h=X-UI-Sender-Class:Content-Type:Message-ID:Date:MIME-Version: Subject:To:References:From:In-Reply-To:cc: content-transfer-encoding:content-type:date:from:message-id: mime-version:reply-to:subject:to; b=HZ8u4OUnIqiOKeSByeJ4ON1MGiErdn7eUNHb7jajUHBM/+KN01l5sb+CvouNmsHK JmerPB/32m0SfrKdV2xKhRtZKbxvkMX6jkziRrZ9l9l62Pp/AsuX29s6fC3eHMsR7 GjQnxCHPwBwKTUn2pOYbTeE/4Rm9RgCMQZggIaTqdoONfmUKKggSuzBtorZxBmiu4 T0fOBMplwRxcPQMOS01eYrFM2D7YiEtf6sS8PePislqy2m7SCkOBY6F782dKyGo+u OHfCQdTHPwNBLkxOzLh2SE5zdFLTTtRsph2yNXTzdSbXPX3lFHhkh8F/f7c9MqRp5 YEAxh+1nN5Vbnn1OXw== X-UI-Sender-Class: 55c96926-9e95-11ee-ae09-1f7a4046a0f6 Received: from client.hidden.invalid by mrelayeu.kundenserver.de (mreue106 [212.227.15.183]) with ESMTPSA (Nemesis) id 1M4aA4-1wSvnu1R2c-00CTcl for <newlib@sourceware.org>; Wed, 03 Jun 2026 02:43:08 +0200 Content-Type: multipart/mixed; boundary="------------IwOxJTYbezHKVuQrEWWYSkxv" Message-ID: <49097df7-bf9a-4710-8e5a-74765d839791@towo.net> Date: Wed, 3 Jun 2026 02:43:09 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH] fix wcwidth to work with gcc 16 sign extension (Re: wchar.h: tweak wcwidth prototype parameter wchar_t -> wint_t) To: newlib@sourceware.org References: <93dc6225-0cd9-4ce0-b042-3ab88249fb7f@towo.net> <91e5dcbd-0675-4aab-9697-32d71d6d0db2@SystematicSW.ab.ca> <3e90a627-569a-4849-9bf8-424493380308@towo.net> <20260531205733.1b25941ba52273f854c9f8d6@nifty.ne.jp> <f0d3d076-ae16-4346-91e3-cae5476c3697@towo.net> From: Thomas Wolff <towo@towo.net> Autocrypt: addr=towo@towo.net; keydata= xsDNBGNaf3QBDACVevqudcTSevLThXKQPU1QpaDxtGuYjtwmr7i9wXxVGih4Y4oxOJN4PYlu KBX9IVAI4651dA+xYtXuyIkWOPZWyyzkGKavQOn3Q7dk09oj7bh2IwOndpxXXde337D408EQ bQEGbMHr9lOWhSAideowzgCeFIvGTf2AovbPh97HpexJn1/HCRiRAhTNlrkS1DByUgCAeEMK fEr6aGM/Ou29MT+eTnQwOIZTnl9Z9LxM2FtqqMH3MycC7I2OoW3XXhuL8BPQdyJUjWa0/J11 Oo5jFkRXtWenIns6jGn18oW72jnDmo9jXwwS+iZWAV6Y51nhD7jSC+3xs9ORmPCdtHUSpTr1 zh67UueUJ3DUUNVuA25Hn/9EJMJ2L60BGUEr88NEB6pcZhmcwdkurAQeYT6t+frzBz2ctsoN BoxP/Xc02yd+z7hXWRRMrJWh9WHlQHA3Z4FfmyNhyPhs3MgKTJ1E9QfzGquigAmF3/k/Dc1m 7cSOKhGYhpEJdSpdXccJFKkAEQEAAc0cVGhvbWFzIFdvbGZmI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VfXkVlbuWpPfUWQeFclLGg8P agpQUE0Ux+VV4DoeQCxYEnRCf/n7n+IRfILj5+2l6Zw4M7zSu6ii0tUAEQEAAcLA9gQYAQgA IBYhBHUiRKsHn5d8BpWdP8bz0e72Bp0CBQJjWn97AhsMAAoJEMbz0e72Bp0CQr4L/REdT0SF mbapnZIe92THCdtAUgwEv8VdNiNFBJelz8P/fuXuNPtisYvQQD4e64zpWe2UC4Cxo9DUk/pW 6Qci1xaXRKEiSPjHdSGGVB1PFIcqiS75GCf/ga/Dnfsy0Y4Uh6OGTQnkvZLBCe3vvcVLDQ7F PuV79zA9/eOeOW6aGoO6bq/wH+z96f9LyTITkQDy07fm6JYTGuzAoJE2AEboU1mgbtlx+tAa QFkpAQkp2g1Vhc3A7k4vntlHOrjMC+uVFh7QTGFfIlLRF6izUjSe6EZ06LErzlIiE05RP3yF FSRWidW0wze26peYlxYVgH1+T9wMTW2oiTBybfAMHBAxUP7Gr1WUo/oJEr0srWhatz8AwydP y7NwFbdpYn0NcFBaIlLW/JL11Eovwlivow+oGpzGFuuzSuflp2q9s2JWtn4EhW0kEs93D0LP iuJWvRaCZ6aD3uF3FMW8wyVWZYsLrzune2jH8w/uKMprDEOGOm+BcyhEFedTyY1ygbZKl+0G kQ== In-Reply-To: <f0d3d076-ae16-4346-91e3-cae5476c3697@towo.net> X-Provags-ID: V03:K1:bnKWWHmQN/mPVlGRSASbwppgoy2+RXanyjXrHIjxOifoYjKS/u6 wnW4naE2jnnVlmTIekBzF59pgznBT3vMcvnwv5uvse3dyq1y/e9rrr7gOl8WdSal2ouNoS5 6kpskCc8aDLdZNY4xrP5p02FOqU7pdYfpaW3kFRmH7WIb30AsSB6ZEdMit2rPTeKAAWVAZ4 1IVPvjkjjR267Qj6H237Q== UI-OutboundReport: notjunk:1;M01:P0:llNWu8VD5H4=;fq4aUUtG6ucrbuuJBrrx9X6vuCW MENaESnmfgLCe2l4RKtnLmQST4vuhym8s8ppeBEt2w6v3zxtDh622DE5qipBT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BGX3+O4k8Zqp5vYpdhlPHPvg g01Jh8ap8zFJPanw0lj45cOI9k7V6GtbGlbUyYN1/YrGWaIM3HClCjyuzjaaRTEM4uZNrtXZh x0YfKVay7ErA/rim2LCcAHNMgqt1uocX8s0Cwe7fCJswP58v+CTAQvGKWEuJbmGTEUErbA0Ct 1cTLqMXoX/LdL3Yj5HwtBueuNZyBAV7+UaUbI2/FCj+usFcadeMHktRBSHx4KGy6ZOF1+DlZs zccz9G+FrMjHZdS2iib6vrGTvuAWGsWoKcYmFW5w/1nVPkf+u1JQvfCIYEke8+NsWZUUaW9u/ lOGfL6NnxHbkc5WMU7ZuNws2WurkTPwCqNG2dO8cps2jd6vlv5pITanMKh7FyPGnkDmArQoQm IPvkuAwlrl9o+9Hek768ubeoaBSyB2eQAPwSAF4/gyKOU8Jyb+esZsRVo1uY5Y/zw9Szxdhqh nw8VpCrUBwLS3kaOHRYkE3oEYjeTDuS59xS4KBtFD8KVrouugJXrIF7QnaSVn8C2DyEERurNy S8btWk27a4gk80pkwjStJ/IulCLk6nwFY3HyDfM4wmU6x7ITD4PH6CskPCob++9EMi+fBj2bu HnNxcptE8rXNQa3WsTUfrPmQtC3F/oUGjFqzllfbITLu/EmSiiOfWJXMf2xPmfWSmNGD2FlPQ bi6cHrOQHSJ7JjUNAjuzyRAresF4ve1MoM/jqRiROm5wi+XPVHIXEdGdfELQh3KMi7qBmMF43 Wp43F0HxM20RRujgVRDG2IZnso54yTJlFOD48+KOAMwBTb3y6zh0gK5jvvH X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP, URIBL_BLOCKED shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list <newlib.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/newlib>, <mailto:newlib-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/newlib/> List-Post: <mailto:newlib@sourceware.org> List-Help: <mailto:newlib-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/newlib>, <mailto:newlib-request@sourceware.org?subject=subscribe> Errors-To: newlib-bounces~patchwork=sourceware.org@sourceware.org |
| Series |
fix wcwidth to work with gcc 16 sign extension (Re: wchar.h: tweak wcwidth prototype parameter wchar_t -> wint_t)
|
|
Commit Message
Thomas Wolff
June 3, 2026, 12:43 a.m. UTC
As discussed in the cygwin thread, I withdraw my previous patch and provide the attached one to fix wcwidth for gcc 16. Thomas Am 01.06.2026 um 18:02 schrieb Thomas Wolff: > > Am 31.05.2026 um 13:57 schrieb Takashi Yano: >> Hi Thomas, >> >> On Sun, 31 May 2026 10:06:12 +0200 >> Thomas Wolff wrote: >>> Hi Brian, >>> >>> Am 31.05.2026 um 05:50 schrieb Brian Inglis via Cygwin: >>>> On 2026-05-28 22:58, Thomas Wolff wrote: >>>>> to make it compliant with newlib and the manual page; >>>>> fixes cases of wrong width calculation: >>>>> https://cygwin.com/pipermail/cygwin/2026-April/259597.html >>>>> as mentioned in >>>>> https://cygwin.com/pipermail/cygwin/2026-May/259734.html >>>>> as described in >>>>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125451#c14 >>>>> attachment: >>>> 0001-wchar.h-tweak-wcwidth-prototype-parameter-wchar_t-wi.patch >>>> >>>> The existing wcwidth declaration in newlib/libc/include/wchar.h agrees >>>> with >>>> POSIX 8 SUS V5. >>>> >>>> It is the man doc, definition, and implementation in >>>> newlib/libc/string/wcwidth.c which need changed to match the >>>> specification and return codes in: >>>> >>>> https://pubs.opengroup.org/onlinepubs/9799919799/functions/wcwidth.html >>>> >>> Your argument overlooks one significant deviation: in POSIX, wchar_t >>> has >>> 32 bits, in cygwin only 16. >>> So to make wcwidth work for *all* Unicode character code points, the 32 >>> bit version must be used. >>> I tested positively that this fixes the broken test case with gcc 16 I >>> had reported to the cygwin list. >> However, newlib is not used only by Cygwin, so I think newlib itself >> should >> follow POSIX. Shouldn't we have our own wcwidth() implementation for >> Cygwin? >> >> On second thought, since a 16‑bit wchar_t needs to be converted to a >> 32‑bit >> Unicode code point especially for surrogate pair, we cannot use >> wcwidth in >> the same way as Linux does. I wonder what the correct approach would be. > I don't there is a "correct" approach as POSIX probably did not > consider this problem. > But I just responded to a cute idea on the cygwin mailing list, which > was unfeasible but I modified it with a proposal to return width 1 for > a high surrogate, remember it, and then return 1 or 0 for the low > surrogate, respectively. From 08f00a6599810e8aa5fc4b456a5b183635ce91fc Mon Sep 17 00:00:00 2001 From: Thomas Wolff <towo@towo.net> Date: Wed, 3 Jun 2026 00:00:00 +0000 Subject: [PATCH] sync wcwidth parameter width with prototype in wchar.h in order to exclude undefined behaviour on parameter width extension as arised at gcc 16, see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125451, fixes https://cygwin.com/pipermail/cygwin/2026-April/259597.html --- newlib/libc/string/wcwidth.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Comments
Patch applied. Thanks. -- Jeff J. On Tue, Jun 2, 2026 at 8:43 PM Thomas Wolff <towo@towo.net> wrote: > As discussed in the cygwin thread, I withdraw my previous patch and > provide the attached one to fix wcwidth for gcc 16. > Thomas > > Am 01.06.2026 um 18:02 schrieb Thomas Wolff: > > > > Am 31.05.2026 um 13:57 schrieb Takashi Yano: > >> Hi Thomas, > >> > >> On Sun, 31 May 2026 10:06:12 +0200 > >> Thomas Wolff wrote: > >>> Hi Brian, > >>> > >>> Am 31.05.2026 um 05:50 schrieb Brian Inglis via Cygwin: > >>>> On 2026-05-28 22:58, Thomas Wolff wrote: > >>>>> to make it compliant with newlib and the manual page; > >>>>> fixes cases of wrong width calculation: > >>>>> https://cygwin.com/pipermail/cygwin/2026-April/259597.html > >>>>> as mentioned in > >>>>> https://cygwin.com/pipermail/cygwin/2026-May/259734.html > >>>>> as described in > >>>>> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125451#c14 > >>>>> attachment: > >>>> 0001-wchar.h-tweak-wcwidth-prototype-parameter-wchar_t-wi.patch > >>>> > >>>> The existing wcwidth declaration in newlib/libc/include/wchar.h agrees > >>>> with > >>>> POSIX 8 SUS V5. > >>>> > >>>> It is the man doc, definition, and implementation in > >>>> newlib/libc/string/wcwidth.c which need changed to match the > >>>> specification and return codes in: > >>>> > >>>> > https://pubs.opengroup.org/onlinepubs/9799919799/functions/wcwidth.html > >>>> > >>> Your argument overlooks one significant deviation: in POSIX, wchar_t > >>> has > >>> 32 bits, in cygwin only 16. > >>> So to make wcwidth work for *all* Unicode character code points, the 32 > >>> bit version must be used. > >>> I tested positively that this fixes the broken test case with gcc 16 I > >>> had reported to the cygwin list. > >> However, newlib is not used only by Cygwin, so I think newlib itself > >> should > >> follow POSIX. Shouldn't we have our own wcwidth() implementation for > >> Cygwin? > >> > >> On second thought, since a 16‑bit wchar_t needs to be converted to a > >> 32‑bit > >> Unicode code point especially for surrogate pair, we cannot use > >> wcwidth in > >> the same way as Linux does. I wonder what the correct approach would be. > > I don't there is a "correct" approach as POSIX probably did not > > consider this problem. > > But I just responded to a cute idea on the cygwin mailing list, which > > was unfeasible but I modified it with a proposal to return width 1 for > > a high surrogate, remember it, and then return 1 or 0 for the low > > surrogate, respectively. >
diff --git a/newlib/libc/string/wcwidth.c b/newlib/libc/string/wcwidth.c index 8348eefe8..dfcaa6c21 100644 --- a/newlib/libc/string/wcwidth.c +++ b/newlib/libc/string/wcwidth.c @@ -230,7 +230,9 @@ __wcwidth (const wint_t ucs) } int -wcwidth (const wint_t wc) +wcwidth (const wchar_t wc) +// parameter width must be in sync with prototype in wchar.h +// to exclude undefined behaviour on parameter width extension (e.g. gcc 16) { wint_t wi = wc;