unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: FACE_FROM_ID vs FACE_OPT_FROM_ID
Date: Fri, 24 Jun 2016 02:23:17 +0200	[thread overview]
Message-ID: <576C7D75.4070401@cs.ucla.edu> (raw)
In-Reply-To: <83d1n73c5z.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 720 bytes --]

On 06/23/2016 10:03 PM, Eli Zaretskii wrote:
> What was the GCC 6.1 complaint that led you to this change?
Diagnostics like this one (there were quite a few):

> xdisp.c: In function 'fill_image_glyph_string':
> xdisp.c:24916:20: error: potential null pointer dereference 
> [-Werror=null-dereference]
>    s->font = s->face->font;
>              ~~~~~~~^~~~~~

The problem being that s->face was set from FACE_FROM_ID, which (before 
the change) might return a null pointer.

The intent is that FACE_FROM_ID returns a face (a non-null pointer), 
whereas FACE_OPT_FROM_ID returns a face option (either a face or a null 
pointer). Similarly for IMAGE_FROM_ID. I installed the attached patch to 
try to make this clearer.

[-- Attachment #2: 0001-Clarify-intent-of-FACE_FROM_ID-and-IMAGE_FROM_ID.txt --]
[-- Type: text/plain, Size: 2012 bytes --]

From b3ef03f646c8fb3dc6d55a8ed0134b6963243f86 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Fri, 24 Jun 2016 02:19:13 +0200
Subject: [PATCH] Clarify intent of FACE_FROM_ID and IMAGE_FROM_ID
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* src/dispextern.h (FACE_OPT_FROM_ID): Don’t use FACE_FROM_ID,
since it is intended to be used only when it returns a non-null
pointer, and here the pointer might be null.
(IMAGE_OPT_FROM_ID): Don’t use IMAGE_FROM_ID, for similar reasons.
---
 src/dispextern.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/dispextern.h b/src/dispextern.h
index d0fc3b2..08dcd89 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -1812,7 +1812,7 @@ struct face_cache
   bool_bf menu_face_changed_p : 1;
 };
 
-/* Return a pointer to the cached face with ID on frame F.  */
+/* Return a non-null pointer to the cached face with ID on frame F.  */
 
 #define FACE_FROM_ID(F, ID)					\
   (eassert (UNSIGNED_CMP (ID, <, FRAME_FACE_CACHE (F)->used)),	\
@@ -1823,7 +1823,7 @@ struct face_cache
 
 #define FACE_OPT_FROM_ID(F, ID)				\
   (UNSIGNED_CMP (ID, <, FRAME_FACE_CACHE (F)->used)	\
-   ? FACE_FROM_ID (F, ID)				\
+   ? FRAME_FACE_CACHE (F)->faces_by_id[ID]		\
    : NULL)
 
 /* True if FACE is suitable for displaying ASCII characters.  */
@@ -3093,7 +3093,7 @@ struct image_cache
 };
 
 
-/* A pointer to the image with id ID on frame F.  */
+/* A non-null pointer to the image with id ID on frame F.  */
 
 #define IMAGE_FROM_ID(F, ID)					\
   (eassert (UNSIGNED_CMP (ID, <, FRAME_IMAGE_CACHE (F)->used)),	\
@@ -3104,7 +3104,7 @@ struct image_cache
 
 #define IMAGE_OPT_FROM_ID(F, ID)				\
   (UNSIGNED_CMP (ID, <, FRAME_IMAGE_CACHE (F)->used)		\
-   ? IMAGE_FROM_ID (F, ID)					\
+   ? FRAME_IMAGE_CACHE (F)->images[ID]				\
    : NULL)
 
 /* Size of bucket vector of image caches.  Should be prime.  */
-- 
2.5.5


  reply	other threads:[~2016-06-24  0:23 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-23 20:03 FACE_FROM_ID vs FACE_OPT_FROM_ID Eli Zaretskii
2016-06-24  0:23 ` Paul Eggert [this message]
2016-06-24  8:49   ` Eli Zaretskii
2016-06-24  9:27     ` Paul Eggert
2016-06-24  9:57       ` Eli Zaretskii
2016-06-24 10:00       ` Eli Zaretskii
2016-06-24 11:17         ` Paul Eggert
2016-06-24 13:43           ` Eli Zaretskii
2016-06-24 21:34             ` Paul Eggert
2016-06-25  7:48               ` Eli Zaretskii
2016-06-25 21:34                 ` Paul Eggert
2016-07-02  9:50                   ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=576C7D75.4070401@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).