]> git.eshelyaron.com Git - emacs.git/commitdiff
Pacify gcc 11.1.1 -Wanalyzer-possible-null-dereference
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 12 Jul 2021 07:06:34 +0000 (00:06 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 12 Jul 2021 07:12:21 +0000 (00:12 -0700)
* 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
oldXMenu/Internal.c
oldXMenu/XMakeAssoc.c
test/src/emacs-module-resources/mod-test.c

index 7eb17c508d57dba66f326e106f681c9ba1d90892..e209bbeceeb5536873bdac1bbd290c18439a41ad 100644 (file)
@@ -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);
 
   /*
index f489e27beab61c7372cbe0436963da2a41ce7013..3e97f9ab3f14d1f9a64098cb84a7159bd681e869 100644 (file)
@@ -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) {
index 9bbde2cf94d726c91cf5cdc0d5f6d50b9b06c575..2530e8e507b6e6a0a695561cbd423a4cbddaa7ef 100644 (file)
@@ -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;
index ad59cfc18cdd6d759c56e3c146a54b4c42f01d54..5720af8c60525c0562b86472a6560a4a63a71387 100644 (file)
@@ -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);
 }