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#73985: fix: charset.max_char may be used before being set Date: Thu, 24 Oct 2024 17:42:36 +0300 Message-ID: <86ldydd0kj.fsf@gnu.org> References: <86plnpd1z6.fsf@gnu.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="20893"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 73985@debbugs.gnu.org To: altermo31@proton.me Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Oct 24 16:43:54 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 1t3z45-0005Fy-86 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 24 Oct 2024 16:43:53 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t3z3r-0005UR-84; Thu, 24 Oct 2024 10:43:39 -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 1t3z3k-0005Ts-SI for bug-gnu-emacs@gnu.org; Thu, 24 Oct 2024 10:43:34 -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 1t3z3k-00024j-Ja for bug-gnu-emacs@gnu.org; Thu, 24 Oct 2024 10:43:32 -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=d5ZyaR6nr6rSvuSEnGgo7rCmBgVCJmE4AMYzraKemcY=; b=eREAQMGA++0Qg6VP6bMwiysv3sS8kdbvImkUNOg6s0ALlVxCl1GTBlzMsSzwBf1OxKlKKvPqQ0JmLo5WSoX5el3CgJcAnxyzWMuEchVq1tsZ3Vwc2KkqdvSd9MTa8M2GXT/UkXt6farn7+4JUYunyKLZYVYJTc+KJymp4AJZ6Ej/hcBP745gqSfk5HbWQZWv2eNl+LV40q34jTztss/5l5fukQXpnRy4B3uCgOZtBItg3HBk6yMl9lsee26veeClI8XzWRRo72TykQ4wgP0ap/Gd3CJMS1JZz7ZwM0uPAnqQ9F2rYmA9dYOBleBtHHk2KARQeHoaYxZslFB8g74TlQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t3z4F-0007bw-0A for bug-gnu-emacs@gnu.org; Thu, 24 Oct 2024 10:44:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 24 Oct 2024 14:44:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73985 X-GNU-PR-Package: emacs Original-Received: via spool by 73985-submit@debbugs.gnu.org id=B73985.172978100429185 (code B ref 73985); Thu, 24 Oct 2024 14:44:02 +0000 Original-Received: (at 73985) by debbugs.gnu.org; 24 Oct 2024 14:43:24 +0000 Original-Received: from localhost ([127.0.0.1]:35855 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t3z3b-0007af-Nd for submit@debbugs.gnu.org; Thu, 24 Oct 2024 10:43:24 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:58344) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t3z3V-0007aL-9w for 73985@debbugs.gnu.org; Thu, 24 Oct 2024 10:43:21 -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 1t3z2u-0001yE-3P; Thu, 24 Oct 2024 10:42:40 -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=d5ZyaR6nr6rSvuSEnGgo7rCmBgVCJmE4AMYzraKemcY=; b=calp/HTKTR3J k2F6uSvCqXcfQWmMWKQJ7I0RGr1ftZntvgcH9nHl3cm0vs8Vqx8QRBLdPafQW9YFWDbzYL8uV3oQg U0WhOD7gofPAURo+8Z8iF8rDl9rF4kRBkHCo19xitrcQC49SqPG3XmQ/kR2eOOKOTEuZQSjy8Ry8g uOfPkmQhN8Yhqc8zGgGaSC2hTznmUpo55sm/0UAzkF74Z4cJ7WGt2WpmbM0d6zrKcGrXlSxG3JoLn LBPy3lIqLHjepKdIQAVB98ChV5Zy+EmntjQ0dYluco+WqsefsC854uwF3C/QJwzCXbPLMn1Rvxi0K fSjbyzNoJDASGBdrcZMh0A==; In-Reply-To: <86plnpd1z6.fsf@gnu.org> (message from Eli Zaretskii on Thu, 24 Oct 2024 17:12:13 +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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:294193 Archived-At: > Cc: 73985@debbugs.gnu.org > Date: Thu, 24 Oct 2024 17:12:13 +0300 > From: Eli Zaretskii > > > Date: Thu, 24 Oct 2024 11:46:17 +0000 > > From: altermo31 via "Bug reports for GNU Emacs, > > the Swiss army knife of text editors" > > > > Problem: > > If the value to be set to charset.max_char is invalid, an error occurs, but the error uses the yet unset charset.max_char. > > > > Solution: > > Use the value that charset.max_char would be set to if the value wasn't invalid. > > Thanks. You are right that the original code is incorrect, but the > code you propose has a subtle problem: the sum > > i + charset.code_offset > > could overflow. So we need to find a safer way of explaining the > problem. I fixed that (on the master branch) like this: diff --git a/src/charset.c b/src/charset.c index e8d0826..f7d80cc 100644 --- a/src/charset.c +++ b/src/charset.c @@ -1007,7 +1007,8 @@ DEFUN ("define-charset-internal", Fdefine_charset_internal, i = CODE_POINT_TO_INDEX (&charset, charset.max_code); if (MAX_CHAR - charset.code_offset < i) - error ("Unsupported max char: %d", charset.max_char); + error ("Unsupported max char: %d + %ud > MAX_CHAR (%d)", + i, charset.max_code, MAX_CHAR); charset.max_char = i + charset.code_offset; i = CODE_POINT_TO_INDEX (&charset, charset.min_code); charset.min_char = i + charset.code_offset;