From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#73307: Fix ctype(3) usage Date: Wed, 18 Sep 2024 14:45:25 +0300 Message-ID: <86r09h9odm.fsf@gnu.org> References: <86r09ibiq3.fsf@gnu.org> <89deb908-92a6-489f-bab9-116556ce8ce4@cs.ucla.edu> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6596"; mail-complaints-to="usenet@ciao.gmane.io" Cc: luangruo@yahoo.com, 73307@debbugs.gnu.org, wiz@gatalith.at To: Paul Eggert , Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 18 13:47:02 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1sqt9B-0001XN-Pe for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 18 Sep 2024 13:47:02 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sqt90-0004Pe-1i; Wed, 18 Sep 2024 07:46:50 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sqt8x-0004PN-8b for bug-gnu-emacs@gnu.org; Wed, 18 Sep 2024 07:46:47 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sqt8w-0003dw-Vj for bug-gnu-emacs@gnu.org; Wed, 18 Sep 2024 07:46:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=References:In-Reply-To:From:Date:To:Subject; bh=1OMXcIvJvmo+OrYU4nZl3kMlbuq+qVEdaYf/EmBZh/U=; b=u3r7zwgikWajlboZyqejxnDDAH6LUitjZDCpQdFOhUkcuEw0lFQt7bRUZILY8ZPaXCfUkdVjGE0Hb4GLeh+bVH8WbmL23WhnZBuZmxZ9g5+YnckmpGlBVkZrOzd0gjIYP2H/p4ADoZctLDaeRqwiZB6SUo4aiNHlMVhoxdpQakR2XFcn7H33iG+kTRPageS2E9O4DgKh1L8w7adkrNPb/zjBNVmIh2C0JxkvwkI6HFB/fRIpwKjGNSlDhiHdLV/Rdm/yWUV71Rx8pM1k/g76Hkxg+sfL1ZH+bhXDcPpt8Z3z/IlKQ7EXx50vsuf0wSHq0iCC95ZH+lYJm3k4T7ZhBg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sqt9B-0006ga-S4 for bug-gnu-emacs@gnu.org; Wed, 18 Sep 2024 07:47:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 18 Sep 2024 11:47:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73307 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 73307-submit@debbugs.gnu.org id=B73307.172665998125625 (code B ref 73307); Wed, 18 Sep 2024 11:47:01 +0000 Original-Received: (at 73307) by debbugs.gnu.org; 18 Sep 2024 11:46:21 +0000 Original-Received: from localhost ([127.0.0.1]:57175 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sqt8W-0006fE-Oy for submit@debbugs.gnu.org; Wed, 18 Sep 2024 07:46:21 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:46826) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sqt8R-0006ew-RQ for 73307@debbugs.gnu.org; Wed, 18 Sep 2024 07:46:19 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sqt80-0003cB-QE; Wed, 18 Sep 2024 07:45:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=1OMXcIvJvmo+OrYU4nZl3kMlbuq+qVEdaYf/EmBZh/U=; b=EMAIa2zNGhNQ OvNPDz9XwEzq9/n6wwYQ3sZ57Xakx1SdPHMp6rSBmUup+Ima2fSUVhY/osPgl50RduZ3q+UhXRGkh GJ2mKcX7l5o5H4FMPVZBV6qHcTpRM/YqO6Ak+goSuHXhsO0uI12b3VtODhb6ni7m1HD8KbrmPosMX sEQfVxk+vFu/yrUyMk6D7ZyXs+bOLUHi3in4U2XEZ0qhq47/6vXRdyMa11jn6fQxwOFHBKbbAcIkh UhZ21HzA7v3p1E7PtOqf0HyciKDbbIJRbOKZI3/nEx5Vt4l6GJXZrakJl47HxKvXFP3M3sY+O8pk/ 8IZR4wjg415PxtYKhHJEGw==; In-Reply-To: <89deb908-92a6-489f-bab9-116556ce8ce4@cs.ucla.edu> (message from Paul Eggert on Tue, 17 Sep 2024 17:05:29 -0700) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:292000 Archived-At: > Date: Tue, 17 Sep 2024 17:05:29 -0700 > Cc: 73307-done@debbugs.gnu.org, Thomas Klausner , > Po Lu > From: Paul Eggert > > On 2024-09-17 04:52, Eli Zaretskii wrote: > > However, I'm not sure this is the right fix, the function is > > defined with argument type of 'int'. Paul, any comments? > > Although that patch was an improvement it still had problems, as it > incorrectly assumed the string does not end in a multibyte space, and > that Emacs's locale matches the system's. > > Emacs itself should not use unless it knows the string is > unibyte and the system locale matches Emacs's. I scanned through its > source code looking for all problematic instances of that have > crept in (except I didn't scan the MS-Windows code, where you're the > expert), and found five other places where ctype.h was obviously > misused. I installed the attached to fix these glitches and am boldly > closing this the report. > > I can't easily test patch 0003, which fixes Android-specific code. > Although I think it's an improvement, in unlikely cases I suspect it > still doesn't exactly match what the Android kernel does with #! lines. > I don't know whether that matters. I'll CC this to Po Lu (my goto person > for Android) as a heads-up. Thanks. This part doesn't look right to me: > - { > - char *s = SSDATA (prompt); > - ptrdiff_t len = strlen (s); > - if ((len > 0) && !isspace (s[len - 1])) > - prompt = CALLN (Fconcat, prompt, build_string (" ")); > - } > - prompt = CALLN (Fconcat, prompt, Vyes_or_no_prompt); > + ptrdiff_t promptlen = SCHARS (prompt); > + bool prompt_ends_in_nonspace > + = (0 < promptlen > + && (SYNTAX (XFIXNAT (Faref (prompt, make_fixnum (promptlen - 1)))) > + != Swhitespace)); > + AUTO_STRING (space_string, " "); > + prompt = CALLN (Fconcat, prompt, > + prompt_ends_in_nonspace ? space_string : empty_unibyte_string, > + Vyes_or_no_prompt); You are testing characters for whitespace syntax, which is AFAIU subject to buffer-local syntax tables. Thus, a strange enough setting of buffer syntax could make this code return unexpected results. Stefan, am I right? Why can't we use something closer to the original code, which doesn't depend on buffer-local customizations? In particular, what's the problem with using c_isspace (and what do you mean by "multibyte space"?)