shell: assert get_shell_surface() != NULL as appropriate

Various functions that operate on a weston_surface assume the
surface has a shell_surface.  That is, they unconditionally
deref the get_shell_surface() result.  Hence, if for some reason
the call to get_shell_surface() returned NULL to those functions then
a segmentation fault would occur and the program would crash.  So,
adding an assert(...) on the get_shell_surface() return value adds an
extra sanity check and does not change this behavior.  The assert also
adds an extra benefit to the programmer by documenting that the function
expects and requires the weston_surface to have a shell_surface and
would be a program logic error, otherwise.

The assert() also silences some static analyzers about the possible
NULL deref.

Signed-off-by: U. Artie Eoff <ullysses.a.eoff@intel.com>
dev
U. Artie Eoff 11 years ago committed by Kristian Høgsberg
parent 0b23b2bd58
commit cf5737aa41
  1. 19
      desktop-shell/shell.c

@ -1578,6 +1578,8 @@ send_configure(struct weston_surface *surface,
{ {
struct shell_surface *shsurf = get_shell_surface(surface); struct shell_surface *shsurf = get_shell_surface(surface);
assert(shsurf);
wl_shell_surface_send_configure(shsurf->resource, wl_shell_surface_send_configure(shsurf->resource,
edges, width, height); edges, width, height);
} }
@ -3258,6 +3260,8 @@ xdg_send_configure(struct weston_surface *surface,
{ {
struct shell_surface *shsurf = get_shell_surface(surface); struct shell_surface *shsurf = get_shell_surface(surface);
assert(shsurf);
xdg_surface_send_configure(shsurf->resource, edges, width, height); xdg_surface_send_configure(shsurf->resource, edges, width, height);
} }
@ -4226,6 +4230,8 @@ activate(struct desktop_shell *shell, struct weston_surface *es,
wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener); wl_signal_add(&es->destroy_signal, &state->surface_destroy_listener);
shsurf = get_shell_surface(main_surface); shsurf = get_shell_surface(main_surface);
assert(shsurf);
if (shsurf->state.fullscreen) if (shsurf->state.fullscreen)
shell_configure_fullscreen(shsurf); shell_configure_fullscreen(shsurf);
else else
@ -4238,7 +4244,7 @@ activate(struct desktop_shell *shell, struct weston_surface *es,
/* Update the surface’s layer. This brings it to the top of the stacking /* Update the surface’s layer. This brings it to the top of the stacking
* order as appropriate. */ * order as appropriate. */
shell_surface_update_layer(get_shell_surface(main_surface)); shell_surface_update_layer(shsurf);
} }
/* no-op func for checking black surface */ /* no-op func for checking black surface */
@ -4716,6 +4722,8 @@ configure(struct desktop_shell *shell, struct weston_surface *surface,
shsurf = get_shell_surface(surface); shsurf = get_shell_surface(surface);
assert(shsurf);
if (shsurf->state.fullscreen) if (shsurf->state.fullscreen)
shell_configure_fullscreen(shsurf); shell_configure_fullscreen(shsurf);
else if (shsurf->state.maximized) { else if (shsurf->state.maximized) {
@ -4744,10 +4752,13 @@ static void
shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy) shell_surface_configure(struct weston_surface *es, int32_t sx, int32_t sy)
{ {
struct shell_surface *shsurf = get_shell_surface(es); struct shell_surface *shsurf = get_shell_surface(es);
struct desktop_shell *shell = shsurf->shell; struct desktop_shell *shell;
int type_changed = 0; int type_changed = 0;
assert(shsurf);
shell = shsurf->shell;
if (!weston_surface_is_mapped(es) && if (!weston_surface_is_mapped(es) &&
!wl_list_empty(&shsurf->popup.grab_link)) { !wl_list_empty(&shsurf->popup.grab_link)) {
remove_popup_grab(shsurf); remove_popup_grab(shsurf);
@ -4784,6 +4795,8 @@ shell_surface_output_destroyed(struct weston_surface *es)
{ {
struct shell_surface *shsurf = get_shell_surface(es); struct shell_surface *shsurf = get_shell_surface(es);
assert(shsurf);
shsurf->saved_position_valid = false; shsurf->saved_position_valid = false;
shsurf->next_state.maximized = false; shsurf->next_state.maximized = false;
shsurf->next_state.fullscreen = false; shsurf->next_state.fullscreen = false;

Loading…
Cancel
Save