From e945f0d19654d153a626ff6627d2bbf36191cef8 Mon Sep 17 00:00:00 2001 From: "Carsten Haitzler (Rasterman)" Date: Wed, 24 Jul 2013 19:22:31 +0900 Subject: [PATCH] ecore-x: fix randr query when noutputs is 0. --- src/lib/ecore_x/xcb/ecore_xcb_randr.c | 22 +++++++++++++--------- src/lib/ecore_x/xlib/ecore_x_randr.c | 20 +++++++++++--------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/lib/ecore_x/xcb/ecore_xcb_randr.c b/src/lib/ecore_x/xcb/ecore_xcb_randr.c index a429b35f03..d74644cd2c 100644 --- a/src/lib/ecore_x/xcb/ecore_xcb_randr.c +++ b/src/lib/ecore_x/xcb/ecore_xcb_randr.c @@ -2672,15 +2672,19 @@ ecore_x_randr_window_outputs_get(Ecore_X_Window window, outputs = ecore_x_randr_crtc_outputs_get(root, crtcs[i], &noutputs); - if (!outputs) - goto _ecore_x_randr_current_output_get_fail_free; - tret = realloc(ret, ((nret + noutputs) * sizeof(Ecore_X_Randr_Output))); - if (!tret) goto _ecore_x_randr_current_output_get_fail_free; - ret = tret; - memcpy(&ret[nret], outputs, (noutputs * sizeof(Ecore_X_Randr_Output))); - nret += noutputs; - free(outputs); - outputs = NULL; + if (outputs) + { + if (noutputs > 0) + { + tret = realloc(ret, ((nret + noutputs) * sizeof(Ecore_X_Randr_Output))); + if (!tret) goto _ecore_x_randr_current_output_get_fail_free; + ret = tret; + memcpy(&ret[nret], outputs, (noutputs * sizeof(Ecore_X_Randr_Output))); + nret += noutputs; + } + free(outputs); + outputs = NULL; + } } free(crtcs); diff --git a/src/lib/ecore_x/xlib/ecore_x_randr.c b/src/lib/ecore_x/xlib/ecore_x_randr.c index 4761732be9..ef1ea40521 100644 --- a/src/lib/ecore_x/xlib/ecore_x_randr.c +++ b/src/lib/ecore_x/xlib/ecore_x_randr.c @@ -1034,17 +1034,19 @@ ecore_x_randr_window_outputs_get(Ecore_X_Window window, int *num) /* try to get the crtc info for this crtc */ if (!(crtc = XRRGetCrtcInfo(_ecore_x_disp, res, crtcs[i]))) continue; - - /* try to reallocate our return variable */ - if ((tret = realloc(ret, ((nret + crtc->noutput) * - sizeof(Ecore_X_Randr_Output))))) + + if (crtc->noutput > 0) { - ret = tret; - memcpy(&ret[nret], crtc->outputs, - (crtc->noutput * sizeof(Ecore_X_Randr_Output))); - nret += crtc->noutput; + /* try to reallocate our return variable */ + if ((tret = realloc(ret, ((nret + crtc->noutput) * + sizeof(Ecore_X_Randr_Output))))) + { + ret = tret; + memcpy(&ret[nret], crtc->outputs, + (crtc->noutput * sizeof(Ecore_X_Randr_Output))); + nret += crtc->noutput; + } } - /* free the crtc info */ XRRFreeCrtcInfo(crtc); }