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.
This commit is contained in:
Paul Eggert 2021-07-12 00:06:34 -07:00
parent 2337869fbf
commit 1a0fe2a518
4 changed files with 20 additions and 19 deletions

View 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);
/*

View 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) {

View 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;

View 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);
}