From 1536bc2d213713af45541a15b5e49c552d8d0592 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sat, 3 Nov 2012 20:23:44 -0400 Subject: cursor: Clean up pointer barrier creation code a tiny bit This will make it much simpler when we add more error paths to the code that constructs pointer barrier clients. Signed-off-by: Jasper St. Pierre Signed-off-by: Peter Hutterer --- xfixes/cursor.c | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) (limited to 'xfixes/cursor.c') diff --git a/xfixes/cursor.c b/xfixes/cursor.c index 75b03749d..f66bd68cb 100644 --- a/xfixes/cursor.c +++ b/xfixes/cursor.c @@ -1245,28 +1245,34 @@ CursorConstrainCursorHarder(DeviceIntPtr dev, ScreenPtr screen, int mode, } } -static struct PointerBarrierClient * +static int CreatePointerBarrierClient(ScreenPtr screen, ClientPtr client, - xXFixesCreatePointerBarrierReq * stuff) + xXFixesCreatePointerBarrierReq * stuff, + PointerBarrierClientPtr *client_out) { CursorScreenPtr cs = GetCursorScreen(screen); struct PointerBarrierClient *ret = malloc(sizeof(*ret)); - if (ret) { - ret->screen = screen; - ret->barrier.x1 = min(stuff->x1, stuff->x2); - ret->barrier.x2 = max(stuff->x1, stuff->x2); - ret->barrier.y1 = min(stuff->y1, stuff->y2); - ret->barrier.y2 = max(stuff->y1, stuff->y2); - ret->barrier.directions = stuff->directions & 0x0f; - if (barrier_is_horizontal(&ret->barrier)) - ret->barrier.directions &= ~(BarrierPositiveX | BarrierNegativeX); - if (barrier_is_vertical(&ret->barrier)) - ret->barrier.directions &= ~(BarrierPositiveY | BarrierNegativeY); - xorg_list_add(&ret->entry, &cs->barriers); + *client_out = NULL; + + if (!ret) { + return BadAlloc; } - return ret; + ret->screen = screen; + ret->barrier.x1 = min(stuff->x1, stuff->x2); + ret->barrier.x2 = max(stuff->x1, stuff->x2); + ret->barrier.y1 = min(stuff->y1, stuff->y2); + ret->barrier.y2 = max(stuff->y1, stuff->y2); + ret->barrier.directions = stuff->directions & 0x0f; + if (barrier_is_horizontal(&ret->barrier)) + ret->barrier.directions &= ~(BarrierPositiveX | BarrierNegativeX); + if (barrier_is_vertical(&ret->barrier)) + ret->barrier.directions &= ~(BarrierPositiveY | BarrierNegativeY); + xorg_list_add(&ret->entry, &cs->barriers); + + *client_out = ret; + return Success; } int @@ -1304,9 +1310,9 @@ ProcXFixesCreatePointerBarrier(ClientPtr client) if (barrier_is_horizontal(&b) && barrier_is_vertical(&b)) return BadValue; - if (!(barrier = CreatePointerBarrierClient(pWin->drawable.pScreen, - client, stuff))) - return BadAlloc; + if ((err = CreatePointerBarrierClient(pWin->drawable.pScreen, + client, stuff, &barrier))) + return err; if (!AddResource(stuff->barrier, PointerBarrierType, &barrier->barrier)) return BadAlloc; -- cgit v1.2.3