emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 1a0fe2a 3/5: Pacify gcc 11.1.1 -Wanalyzer-possible-null-dereferen


From: Paul Eggert
Subject: master 1a0fe2a 3/5: Pacify gcc 11.1.1 -Wanalyzer-possible-null-dereference
Date: Mon, 12 Jul 2021 03:12:30 -0400 (EDT)

branch: master
commit 1a0fe2a5184cd4c57972994cf4b688042aecc534
Author: Paul Eggert <eggert@cs.ucla.edu>
Commit: Paul Eggert <eggert@cs.ucla.edu>

    Pacify gcc 11.1.1 -Wanalyzer-possible-null-dereference
    
    * oldXMenu/Create.c (XMenuCreate):
    * oldXMenu/Internal.c (_XMRecomputePane, _XMRecomputeSelection):
    * oldXMenu/XMakeAssoc.c (XMakeAssoc):
    * test/src/emacs-module-resources/mod-test.c (Fmod_test_userptr_make):
    Don’t assume that malloc and calloc succeed.
---
 oldXMenu/Create.c                          |  2 ++
 oldXMenu/Internal.c                        | 31 ++++++++++++------------------
 oldXMenu/XMakeAssoc.c                      |  2 ++
 test/src/emacs-module-resources/mod-test.c |  4 ++++
 4 files changed, 20 insertions(+), 19 deletions(-)

diff --git a/oldXMenu/Create.c b/oldXMenu/Create.c
index 7eb17c5..e209bbe 100644
--- a/oldXMenu/Create.c
+++ b/oldXMenu/Create.c
@@ -598,6 +598,8 @@ XMenuCreate(Display *display, Window parent, register char 
const *def_env)
    * Create pane, active, and inactive GC's.
    */
   values = (XGCValues *)malloc(sizeof(XGCValues));
+  if (!values)
+    return NULL;
   valuemask = (GCForeground | GCBackground | GCFont | GCLineWidth);
 
   /*
diff --git a/oldXMenu/Internal.c b/oldXMenu/Internal.c
index f489e27..3e97f9a 100644
--- a/oldXMenu/Internal.c
+++ b/oldXMenu/Internal.c
@@ -534,7 +534,6 @@ _XMRecomputePane(register Display *display, register XMenu 
*menu, register XMPan
     register int window_y;     /* Recomputed window Y coordinate. */
 
     unsigned long change_mask; /* Value mask to reconfigure window. */
-    XWindowChanges *changes;   /* Values to use in configure window. */
 
     register Bool config_p = False;    /* Reconfigure pane window? */
 
@@ -612,21 +611,19 @@ _XMRecomputePane(register Display *display, register 
XMenu *menu, register XMPan
         * it for creation with the new configuration.
         */
        if (p_ptr->window) {
+           XWindowChanges changes;
            change_mask = (CWX | CWY | CWWidth | CWHeight);
-           changes = (XWindowChanges *)malloc(sizeof(XWindowChanges));
-           changes->x = p_ptr->window_x;
-           changes->y = p_ptr->window_y;
-           changes->width = p_ptr->window_w;
-           changes->height = p_ptr->window_h;
+           changes.x = p_ptr->window_x;
+           changes.y = p_ptr->window_y;
+           changes.width = p_ptr->window_w;
+           changes.height = p_ptr->window_h;
 
            XConfigureWindow(
                             display,
                             p_ptr->window,
                             change_mask,
-                            changes
+                            &changes
                             );
-           free(changes);
-
        }
        else {
            if (_XMWinQueAddPane(display, menu, p_ptr) == _FAILURE) {
@@ -681,7 +678,6 @@ _XMRecomputeSelection(register Display *display, register 
XMenu *menu, register
                                        /* Selection sequence number. */
 {
     register Bool config_s = False;    /* Reconfigure selection window? */
-    XWindowChanges *changes;           /* Values to change in configure. */
     unsigned long change_mask;         /* Value mask for XConfigureWindow. */
 
     /*
@@ -738,22 +734,19 @@ _XMRecomputeSelection(register Display *display, register 
XMenu *menu, register
         * for creation with the new configuration.
         */
        if (s_ptr->window) {
-           changes = (XWindowChanges *)malloc(sizeof(XWindowChanges));
+           XWindowChanges changes;
            change_mask = (CWX | CWY | CWWidth | CWHeight);
-           changes = (XWindowChanges *)malloc(sizeof(XWindowChanges));
-           changes->x = s_ptr->window_x;
-           changes->y = s_ptr->window_y;
-           changes->width = s_ptr->window_w;
-           changes->height = s_ptr->window_h;
+           changes.x = s_ptr->window_x;
+           changes.y = s_ptr->window_y;
+           changes.width = s_ptr->window_w;
+           changes.height = s_ptr->window_h;
 
            XConfigureWindow(
                             display,
                             s_ptr->window,
                             change_mask,
-                            changes
+                            &changes
                             );
-           free(changes);
-
        }
        else {
            if (_XMWinQueAddSelection(display, menu, s_ptr) == _FAILURE) {
diff --git a/oldXMenu/XMakeAssoc.c b/oldXMenu/XMakeAssoc.c
index 9bbde2c..2530e8e 100644
--- a/oldXMenu/XMakeAssoc.c
+++ b/oldXMenu/XMakeAssoc.c
@@ -69,6 +69,8 @@ XMakeAssoc(register Display *dpy, register XAssocTable 
*table, register XID x_id
        /* before the current value of "Entry". */
        /* Create a new XAssoc and load it with new provided data. */
        new_entry = (XAssoc *) malloc(sizeof(XAssoc));
+       if (!new_entry)
+         return; /* This obsolete API has no way to report failure!  */
        new_entry->display = dpy;
        new_entry->x_id = x_id;
        new_entry->data = data;
diff --git a/test/src/emacs-module-resources/mod-test.c 
b/test/src/emacs-module-resources/mod-test.c
index ad59cfc..5720af8 100644
--- a/test/src/emacs-module-resources/mod-test.c
+++ b/test/src/emacs-module-resources/mod-test.c
@@ -288,6 +288,8 @@ struct super_struct
   char large_unused_buffer[512];
 };
 
+static void signal_errno (emacs_env *, char const *);
+
 /* Return a new user-pointer to a super_struct, with amazing_int set
    to the passed parameter.  */
 static emacs_value
@@ -295,6 +297,8 @@ Fmod_test_userptr_make (emacs_env *env, ptrdiff_t nargs, 
emacs_value args[],
                        void *data)
 {
   struct super_struct *p = calloc (1, sizeof *p);
+  if (!p)
+    signal_errno (env, "calloc");
   p->amazing_int = env->extract_integer (env, args[0]);
   return env->make_user_ptr (env, free, p);
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]