From unknown Tue Jun 17 21:53:31 2025 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Mailer: MIME-tools 5.509 (Entity 5.509) Content-Type: text/plain; charset=utf-8 From: bug#41125 <41125@debbugs.gnu.org> To: bug#41125 <41125@debbugs.gnu.org> Subject: Status: 28.0.50; Fwindow_text_pixel_size uses FETCH_CHAR (charpos) Reply-To: bug#41125 <41125@debbugs.gnu.org> Date: Wed, 18 Jun 2025 04:53:31 +0000 retitle 41125 28.0.50; Fwindow_text_pixel_size uses FETCH_CHAR (charpos) reassign 41125 emacs submitter 41125 Pip Cet severity 41125 normal thanks From debbugs-submit-bounces@debbugs.gnu.org Thu May 07 07:55:47 2020 Received: (at submit) by debbugs.gnu.org; 7 May 2020 11:55:47 +0000 Received: from localhost ([127.0.0.1]:42313 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jWf7z-0004dr-BV for submit@debbugs.gnu.org; Thu, 07 May 2020 07:55:47 -0400 Received: from lists.gnu.org ([209.51.188.17]:38892) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jWf7x-0004dh-Rg for submit@debbugs.gnu.org; Thu, 07 May 2020 07:55:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35776) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jWf7x-0005p4-JF for bug-gnu-emacs@gnu.org; Thu, 07 May 2020 07:55:45 -0400 Received: from mail-oi1-x231.google.com ([2607:f8b0:4864:20::231]:46562) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jWf7w-0007fI-V7 for bug-gnu-emacs@gnu.org; Thu, 07 May 2020 07:55:45 -0400 Received: by mail-oi1-x231.google.com with SMTP id c124so4688490oib.13 for ; Thu, 07 May 2020 04:55:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=6CBWw2AglR7NnqTGpMSxFJInlquqvIrjqG27YaHLgR8=; b=WTNk9xgFgnTC8wh7hQ5cd7fTy+wFieUrFgWLSfYooQ7UmziHaapLTHarhpZ9QsOpr4 K5kKD/x2ST77l7O0hIgouJGn+e7tXIoX8MOsupawqrL7udaXlfZYyt3VNhZnUU2Og5Bq rjymgn35cAmMxMdycTyIJzZOxaE1MiTPAJuLG+KdpJifa/m7Ukd/jEG7ktF6Sz6ZCeUD ML8DDfxEBnEU2TTPsyDWRAtS5JxcNxdNad+Mppsv+JTrAT4Bnqq2+Sb1IdKbqHHfp3As Ns9g3fL2yQoGBWS8H5/rkP6whqNcKZLfaEaSLqlzgRd+PYNNjsKx6TRtITyYTh5tNhDj PymA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=6CBWw2AglR7NnqTGpMSxFJInlquqvIrjqG27YaHLgR8=; b=lYJBET6C82kj/4S/5HQfjSOZiXYKfxrIURDSzprezW9dlVTr1eU8cnLexiU8NcvbVc 1nvpq9GBEunWrv9Y1YW4IKDGkL7RwyOPDeArNlrubxcfEr5dwjP6ZVMlulU4PJS1vBdh xWXcnPfV3CF+oOyV93P9SV+B2ZCyhgTdsEybOHCkcOZpKo87t6/BKYyhtWRVd7TZrR+J gd+PqBvrTEqV/vYL9joe4hKTzRDT1rI/aHPHg+ie8ITGJgkUBq6mxZYAuvDQzL5PsKt8 95w3q0HXhKkOy1TgjZ2uhMvRCGL1wtRm4wlPpLo+Lwjvpxxy3lQKyTYj0LQcKamOKR9p aJ3Q== X-Gm-Message-State: AGi0PubGIp3iKYrs3WllXvZBM/Ior62Lg9FcqALfTB3m5hnYIbsSARFF GfQ5+WAPZG6UKicVXyAv/dlLPVox8Sbq2w/rspBQRY+AHHY= X-Google-Smtp-Source: APiQypK6euTwvaNGMlE9scTEY01iUYnWVjghyUKWftBeZS5rbRJPz/pM2edm0gDTPnp+GmYkVcb9fba1NtgBADpDeWI= X-Received: by 2002:aca:5614:: with SMTP id k20mr6164804oib.30.1588852543566; Thu, 07 May 2020 04:55:43 -0700 (PDT) MIME-Version: 1.0 From: Pip Cet Date: Thu, 7 May 2020 11:55:07 +0000 Message-ID: Subject: 28.0.50; Fwindow_text_pixel_size uses FETCH_CHAR (charpos) To: bug-gnu-emacs@gnu.org Content-Type: text/plain; charset="UTF-8" Received-SPF: pass client-ip=2607:f8b0:4864:20::231; envelope-from=pipcet@gmail.com; helo=mail-oi1-x231.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-Spam-Score: 0.7 (/) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) Fwindow_text_pixel_size contains this code: start = pos = BEGV; while ((pos++ < ZV) && (c = FETCH_CHAR (pos)) && (c == ' ' || c == '\t' || c == '\n' || c == '\r')) start = pos; while ((pos-- > BEGV) && (c = FETCH_CHAR (pos)) && (c == ' ' || c == '\t')) start = pos; which cannot possibly be correct: FETCH_CHAR takes a byte position, not a character position, but BEGV and ZV are measured in characters. (I'm familiarizing myself with the xdisp.c code, partly by replacing bytepos/charpos pairs of variables with a combined pos_t type variable. I think that's a good idea partly because it would prevent precisely this kind of bug.) From debbugs-submit-bounces@debbugs.gnu.org Thu May 07 09:36:44 2020 Received: (at 41125) by debbugs.gnu.org; 7 May 2020 13:36:44 +0000 Received: from localhost ([127.0.0.1]:42423 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jWghf-0007jO-PH for submit@debbugs.gnu.org; Thu, 07 May 2020 09:36:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:57168) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jWghe-0007jD-Lm for 41125@debbugs.gnu.org; Thu, 07 May 2020 09:36:43 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:50225) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jWghX-0000wE-2d; Thu, 07 May 2020 09:36:37 -0400 Received: from [176.228.60.248] (port=1836 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1jWghW-0000Nq-FZ; Thu, 07 May 2020 09:36:34 -0400 Date: Thu, 07 May 2020 16:36:19 +0300 Message-Id: <83mu6jkgto.fsf@gnu.org> From: Eli Zaretskii To: Pip Cet , martin rudalics In-Reply-To: (message from Pip Cet on Thu, 7 May 2020 11:55:07 +0000) Subject: Re: bug#41125: 28.0.50; Fwindow_text_pixel_size uses FETCH_CHAR (charpos) References: X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 41125 Cc: 41125@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Pip Cet > Date: Thu, 7 May 2020 11:55:07 +0000 > > Fwindow_text_pixel_size contains this code: > > start = pos = BEGV; > while ((pos++ < ZV) && (c = FETCH_CHAR (pos)) > && (c == ' ' || c == '\t' || c == '\n' || c == '\r')) > start = pos; > while ((pos-- > BEGV) && (c = FETCH_CHAR (pos)) && (c == ' ' || > c == '\t')) > start = pos; > > which cannot possibly be correct: FETCH_CHAR takes a byte position, > not a character position, but BEGV and ZV are measured in characters. Ouch! Thanks. Does the patch below look good? > (I'm familiarizing myself with the xdisp.c code, partly by replacing > bytepos/charpos pairs of variables with a combined pos_t type > variable. I think that's a good idea partly because it would prevent > precisely this kind of bug.) It might be good for a development build, but not for production: walking the buffer must be very efficient. diff --git a/src/xdisp.c b/src/xdisp.c index 19f4f32..c15dd47 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -10442,7 +10442,7 @@ height (excluding the height of the mode- or header-line, if any) that struct buffer *b; struct it it; struct buffer *old_b = NULL; - ptrdiff_t start, end, pos; + ptrdiff_t start, end, bpos; struct text_pos startp; void *itdata = NULL; int c, max_x = 0, max_y = 0, x = 0, y = 0; @@ -10457,32 +10457,56 @@ height (excluding the height of the mode- or header-line, if any) that } if (NILP (from)) - start = BEGV; + { + start = BEGV; + bpos = BEGV_BYTE; + } else if (EQ (from, Qt)) { - start = pos = BEGV; - while ((pos++ < ZV) && (c = FETCH_CHAR (pos)) - && (c == ' ' || c == '\t' || c == '\n' || c == '\r')) - start = pos; - while ((pos-- > BEGV) && (c = FETCH_CHAR (pos)) && (c == ' ' || c == '\t')) - start = pos; + start = BEGV; + bpos = BEGV_BYTE; + while (bpos < ZV_BYTE) + { + FETCH_CHAR_ADVANCE (c, start, bpos); + if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r')) + break; + } + while (bpos > BEGV_BYTE) + { + DEC_BOTH (start, bpos); + c = FETCH_CHAR (bpos); + if (!(c == ' ' || c == '\t')) + break; + } } else { CHECK_FIXNUM_COERCE_MARKER (from); start = min (max (XFIXNUM (from), BEGV), ZV); + bpos = CHAR_TO_BYTE (start); } + SET_TEXT_POS (startp, start, bpos); + if (NILP (to)) end = ZV; else if (EQ (to, Qt)) { - end = pos = ZV; - while ((pos-- > BEGV) && (c = FETCH_CHAR (pos)) - && (c == ' ' || c == '\t' || c == '\n' || c == '\r')) - end = pos; - while ((pos++ < ZV) && (c = FETCH_CHAR (pos)) && (c == ' ' || c == '\t')) - end = pos; + end = ZV; + bpos = ZV_BYTE; + while (bpos > BEGV_BYTE) + { + DEC_BOTH (end, bpos); + c = FETCH_CHAR (bpos); + if (!(c == ' ' || c == '\t' || c == '\n' || c == '\r')) + break; + } + while (bpos < ZV_BYTE) + { + FETCH_CHAR_ADVANCE (c, end, bpos); + if (!(c == ' ' || c == '\t')) + break; + } } else { @@ -10499,7 +10523,6 @@ height (excluding the height of the mode- or header-line, if any) that max_y = XFIXNUM (y_limit); itdata = bidi_shelve_cache (); - SET_TEXT_POS (startp, start, CHAR_TO_BYTE (start)); start_display (&it, w, startp); /* It makes no sense to measure dimensions of region of text that crosses the point where bidi reordering changes scan direction. From debbugs-submit-bounces@debbugs.gnu.org Fri May 08 03:18:38 2020 Received: (at 41125) by debbugs.gnu.org; 8 May 2020 07:18:38 +0000 Received: from localhost ([127.0.0.1]:44516 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jWxHK-0006pj-A9 for submit@debbugs.gnu.org; Fri, 08 May 2020 03:18:38 -0400 Received: from mout.gmx.net ([212.227.17.22]:52873) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jWxHH-0006pV-Sm for 41125@debbugs.gnu.org; Fri, 08 May 2020 03:18:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1588922309; bh=k5VDllZ9Fg520mJZU3J5I5BbPbfbXRJUY0VV14ZfDqU=; h=X-UI-Sender-Class:Subject:To:Cc:References:From:Date:In-Reply-To; b=RCuK26j66Vm+4PsO8Y7WVQDoFDyLDgq/xMwznKs3qA2hSO/SKmczSkBcWOdW55e7j 5gHedaQpr1Nb91rzlfmda/0QJT5bHGsCxrVQEA5jERkdfbJexW0ax4cgjfd55Wm6SE 58hbg/SBFxYd7o0/k5pAyzEe/DjPlJVEN30ungps= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from [192.168.1.101] ([212.95.5.16]) by mail.gmx.com (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MQe5u-1jjgRP15gU-00Nhjk; Fri, 08 May 2020 09:18:29 +0200 Subject: Re: bug#41125: 28.0.50; Fwindow_text_pixel_size uses FETCH_CHAR (charpos) To: Eli Zaretskii , Pip Cet References: <83mu6jkgto.fsf@gnu.org> From: martin rudalics Message-ID: Date: Fri, 8 May 2020 09:18:27 +0200 MIME-Version: 1.0 In-Reply-To: <83mu6jkgto.fsf@gnu.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K1:BgZ+o4H9yTiUxGgb4svXS6y26OiKdzRZr56ph5VuZaBSvca2XH2 Gwb55FhZzZnV+LMEy4Qixf2G4pSewSL3xP9Zhj8Cz5h72nRwjlESs/61s2tJWb7bQ6PrPXG lYd7loYoSuXXmRytjvQWKLUcHRmewrQ2AeBE6drtfxeoUb5iTzsLZDkXKQnm9ZrtcWQyhUE kXOQ98FwyLpV/NHOJnVNA== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:Z1gaKwxMreg=:o57pG02INSj/kGn0X6bW+b +HkzBBn+JyVRzE7otBfch8a2FITuLRan9lIDmpqtysGJtCioL1Hx1KGwKqFStVpvkEhxiPeMx rIrw4tuF6QtLME3mWjRJ5smy5GE2mgHmhecmTS/4u48zaYzpTywJdGwM/tzc9a3rNxrfsf6gb Kim39rDEQX6V+FC/Ytm58moZaFhSYSWDFCeRiP8KCbicQZQB4wanSgn0kUDXdQJ2nQ3iLHsn8 c5A6HXa2fnIYg+O6lN1Piupnv7baEc2dcOXtHz5NunG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submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.7 (-) >> which cannot possibly be correct: FETCH_CHAR takes a byte position, >> not a character position, but BEGV and ZV are measured in characters. > > Ouch! Thanks. Does the patch below look good? It does. Thanks for fixing yet another of my blunders in this function. And thanks to Pip for catching it. martin From debbugs-submit-bounces@debbugs.gnu.org Fri May 08 06:38:04 2020 Received: (at 41125-done) by debbugs.gnu.org; 8 May 2020 10:38:04 +0000 Received: from localhost ([127.0.0.1]:44664 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jX0OK-0003VQ-1a for submit@debbugs.gnu.org; Fri, 08 May 2020 06:38:04 -0400 Received: from eggs.gnu.org ([209.51.188.92]:46382) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jX0OH-0003Ub-Uq for 41125-done@debbugs.gnu.org; Fri, 08 May 2020 06:38:02 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:49762) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jX0OC-0002Kg-63; Fri, 08 May 2020 06:37:56 -0400 Received: from [176.228.60.248] (port=3124 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1jX0OA-0002f4-P7; Fri, 08 May 2020 06:37:55 -0400 Date: Fri, 08 May 2020 13:37:42 +0300 Message-Id: <83sggaiufd.fsf@gnu.org> From: Eli Zaretskii To: martin rudalics In-Reply-To: (message from martin rudalics on Fri, 8 May 2020 09:18:27 +0200) Subject: Re: bug#41125: 28.0.50; Fwindow_text_pixel_size uses FETCH_CHAR (charpos) References: <83mu6jkgto.fsf@gnu.org> X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 41125-done Cc: 41125-done@debbugs.gnu.org, pipcet@gmail.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > Cc: 41125@debbugs.gnu.org > From: martin rudalics > Date: Fri, 8 May 2020 09:18:27 +0200 > > >> which cannot possibly be correct: FETCH_CHAR takes a byte position, > >> not a character position, but BEGV and ZV are measured in characters. > > > > Ouch! Thanks. Does the patch below look good? > > It does. Thanks for fixing yet another of my blunders in this function. > And thanks to Pip for catching it. Thanks, I pushed the fix to the emacs-27 branch. From unknown Tue Jun 17 21:53:31 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Fri, 05 Jun 2020 11:24:05 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator