Subject: bug#73985: closed (Re: bug#73985: fix: charset.max_char may be used before being set)

From: [email-masked] (GNU bug Tracking System)
Date: Sat, 09 Nov 2024 09:13:02 +0000

Your bug report

#73985: fix: charset.max_char may be used before being set

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
73985: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=73985
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#73985: fix: charset.max_char may be used before being set
From: Eli Zaretskii <[email-masked]>
To: [email-masked]
Cc: [email-masked]
Date: Sat, 09 Nov 2024 11:12:22 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

> Cc: [email-masked]
> Date: Thu, 24 Oct 2024 17:42:36 +0300
> From: Eli Zaretskii <[email-masked]>
> 
> > 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;

No further comments, so I'm now closing this bug.

Subject: fix: charset.max_char may be used before being set
From: altermo31 <[email-masked]>
To: "[email-masked]" <[email-masked]>
Date: Thu, 24 Oct 2024 11:46:17 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

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.

From 64e9557c5f6ae4416a1a12fd6f68f0d19931bb99 Mon Sep 17 00:00:00 2001
From: altermo <[email-masked]>
Date: Thu, 24 Oct 2024 13:39:06 +0200
Subject: [PATCH] fix: charset.max_char may be used before being set

---
 src/charset.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/charset.c b/src/charset.c
index e8d0826..14b33d2 100644
--- a/src/charset.c
+++ b/src/charset.c
@@ -1007,7 +1007,7 @@ 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", i + charset.code_offset);
       charset.max_char = i + charset.code_offset;
       i = CODE_POINT_TO_INDEX (&charset, charset.min_code);
       charset.min_char = i + charset.code_offset;
-- 
2.47.0