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#50752: 28.0.50; easy-menu-define lowers the menu-bar key Date: Fri, 15 Oct 2021 08:59:22 +0300 Message-ID: <83v91ykev9.fsf@gnu.org> References: <87bl4jvudm.fsf@gnus.org> <837dehp248.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="25909"; mail-complaints-to="usenet@ciao.gmane.io" Cc: shuguang79@qq.com, larsi@gnus.org, 50752@debbugs.gnu.org To: stefan@marxist.se Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Oct 15 08:01:00 2021 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 1mbGH6-0006YD-R0 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 15 Oct 2021 08:01:00 +0200 Original-Received: from localhost ([::1]:39900 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mbGH5-0000MS-3N for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 15 Oct 2021 02:00:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51838) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mbGGA-0000MJ-O8 for bug-gnu-emacs@gnu.org; Fri, 15 Oct 2021 02:00:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54432) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mbGGA-0004Vv-C4 for bug-gnu-emacs@gnu.org; Fri, 15 Oct 2021 02:00:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mbGGA-0006Ef-0T for bug-gnu-emacs@gnu.org; Fri, 15 Oct 2021 02:00:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 15 Oct 2021 06:00:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50752 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 50752-submit@debbugs.gnu.org id=B50752.163427757823911 (code B ref 50752); Fri, 15 Oct 2021 06:00:01 +0000 Original-Received: (at 50752) by debbugs.gnu.org; 15 Oct 2021 05:59:38 +0000 Original-Received: from localhost ([127.0.0.1]:37745 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mbGFl-0006Db-Sl for submit@debbugs.gnu.org; Fri, 15 Oct 2021 01:59:38 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:49920) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mbGFh-0006DK-Pl for 50752@debbugs.gnu.org; Fri, 15 Oct 2021 01:59:36 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:48372) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mbGFZ-0001rs-GS; Fri, 15 Oct 2021 01:59:25 -0400 Original-Received: from [87.69.77.57] (port=2624 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mbGFZ-0002vw-3f; Fri, 15 Oct 2021 01:59:25 -0400 In-Reply-To: <837dehp248.fsf@gnu.org> (message from Eli Zaretskii on Wed, 13 Oct 2021 14:59:03 +0300) 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" Xref: news.gmane.io gmane.emacs.bugs:217280 Archived-At: > Date: Wed, 13 Oct 2021 14:59:03 +0300 > From: Eli Zaretskii > Cc: shuguang79@qq.com, larsi@gnus.org, 50752@debbugs.gnu.org > > > + USE_SAFE_ALLOCA; > > + ptrdiff_t size = SCHARS (lc_key), n; > > + if (INT_MULTIPLY_WRAPV (size, MAX_MULTIBYTE_LENGTH, &n)) > > + n = PTRDIFF_MAX; > > + unsigned char *dst = SAFE_ALLOCA (n); > > + unsigned char *o = dst; > > + ptrdiff_t j = 0, j_byte = 0, chars = 0; > > + > > + while (j < SCHARS (lc_key)) > > + { > > + int ch = fetch_string_char_advance (lc_key, &j, &j_byte); > > + if (ch == ' ') > > + *o = '-'; > > + else > > + *o = ch; > > + chars++; > > This will only work with plain-ASCII characters in lc_key (but then > you don't need fetch_string_char_advance, you can access the bytes one > by one). You need to use CHAR_STRING instead. Thinking more about this, you don't need all these complications with fetch_string_char_advance and CHAR_STRING. Since all you need is replace ' ' with '-', you can walk the string data byte by byte, because UTF-8 encoding makes sure no other byte of any multibyte sequence will ever include a 7-bit byte equal to an ASCII single-byte character. So just checking the bytes for equality to ' ' is enough. Thus, you could make a copy of the symbol's name, then walk that copy byte by byte looking for space characters and replacing them. Moreover, you could check up front, using 'strstr', whether the symbol's name includes any space characters, and if not, short-circuit the entire second attempt. These two measures should make the code faster and easier to program and understand.