forked from enlightenment/efl
Be a lot more pedantic and add some more safety checks about xrandr
return values (ie: if xrandr returns 0 crtcs, then we don't need to allocate anything, etc, etc, etc). Signed-off-by: Christopher Michael <cp.michael@samsung.com> SVN revision: 83624
This commit is contained in:
parent
0c76117e1e
commit
562b278b52
|
@ -349,6 +349,8 @@ ecore_x_randr_screen_primary_output_refresh_rates_get(Ecore_X_Window root, int s
|
||||||
{
|
{
|
||||||
Ecore_X_Randr_Refresh_Rate *ret = NULL;
|
Ecore_X_Randr_Refresh_Rate *ret = NULL;
|
||||||
|
|
||||||
|
if (n == 0) return NULL;
|
||||||
|
|
||||||
/* try to allocate space for the return */
|
/* try to allocate space for the return */
|
||||||
if ((ret = malloc(n * sizeof(Ecore_X_Randr_Refresh_Rate))))
|
if ((ret = malloc(n * sizeof(Ecore_X_Randr_Refresh_Rate))))
|
||||||
{
|
{
|
||||||
|
@ -510,6 +512,8 @@ ecore_x_randr_screen_reset(Ecore_X_Window root)
|
||||||
|
|
||||||
/* try to get the screen resources from Xrandr */
|
/* try to get the screen resources from Xrandr */
|
||||||
if ((res = _ecore_x_randr_screen_resources_get(_ecore_x_disp, root)))
|
if ((res = _ecore_x_randr_screen_resources_get(_ecore_x_disp, root)))
|
||||||
|
{
|
||||||
|
if (res->ncrtc > 0)
|
||||||
{
|
{
|
||||||
Ecore_X_Randr_Crtc crtcs[res->ncrtc];
|
Ecore_X_Randr_Crtc crtcs[res->ncrtc];
|
||||||
int i = 0, nenabled = 0;
|
int i = 0, nenabled = 0;
|
||||||
|
@ -562,6 +566,7 @@ ecore_x_randr_screen_reset(Ecore_X_Window root)
|
||||||
|
|
||||||
ecore_x_randr_screen_current_size_set(root, nw, nh, -1, -1);
|
ecore_x_randr_screen_current_size_set(root, nw, nh, -1, -1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -766,6 +771,14 @@ ecore_x_randr_mode_info_get(Ecore_X_Window root, Ecore_X_Randr_Mode mode)
|
||||||
Ecore_X_Randr_Mode_Info *ret = NULL;
|
Ecore_X_Randr_Mode_Info *ret = NULL;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
|
if (res->nmode == 0)
|
||||||
|
{
|
||||||
|
/* free the resources */
|
||||||
|
XRRFreeScreenResources(res);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* loop the mode informations and find the one we want */
|
/* loop the mode informations and find the one we want */
|
||||||
for (i = 0; i < res->nmode; i++)
|
for (i = 0; i < res->nmode; i++)
|
||||||
{
|
{
|
||||||
|
@ -853,6 +866,14 @@ ecore_x_randr_crtcs_get(Ecore_X_Window root, int *num)
|
||||||
{
|
{
|
||||||
Ecore_X_Randr_Crtc *ret = NULL;
|
Ecore_X_Randr_Crtc *ret = NULL;
|
||||||
|
|
||||||
|
if (res->ncrtc == 0)
|
||||||
|
{
|
||||||
|
/* free the resources */
|
||||||
|
XRRFreeScreenResources(res);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* try to allocate space for our return variable */
|
/* try to allocate space for our return variable */
|
||||||
if ((ret = malloc(res->ncrtc * sizeof(Ecore_X_Randr_Crtc))))
|
if ((ret = malloc(res->ncrtc * sizeof(Ecore_X_Randr_Crtc))))
|
||||||
{
|
{
|
||||||
|
@ -888,6 +909,14 @@ ecore_x_randr_outputs_get(Ecore_X_Window root, int *num)
|
||||||
{
|
{
|
||||||
Ecore_X_Randr_Output *ret = NULL;
|
Ecore_X_Randr_Output *ret = NULL;
|
||||||
|
|
||||||
|
if (res->noutput == 0)
|
||||||
|
{
|
||||||
|
/* free the resources */
|
||||||
|
XRRFreeScreenResources(res);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* try to allocate space for our return variable */
|
/* try to allocate space for our return variable */
|
||||||
if ((ret = malloc(res->noutput * sizeof(Ecore_X_Randr_Output))))
|
if ((ret = malloc(res->noutput * sizeof(Ecore_X_Randr_Output))))
|
||||||
{
|
{
|
||||||
|
@ -1195,6 +1224,17 @@ ecore_x_randr_crtc_possible_outputs_get(Ecore_X_Window root, Ecore_X_Randr_Crtc
|
||||||
/* try to get crtc info */
|
/* try to get crtc info */
|
||||||
if ((info = XRRGetCrtcInfo(_ecore_x_disp, res, crtc)))
|
if ((info = XRRGetCrtcInfo(_ecore_x_disp, res, crtc)))
|
||||||
{
|
{
|
||||||
|
if (info->npossible == 0)
|
||||||
|
{
|
||||||
|
/* free the crtc info */
|
||||||
|
XRRFreeCrtcInfo(info);
|
||||||
|
|
||||||
|
/* free the resources */
|
||||||
|
XRRFreeScreenResources(res);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* try to allocate our return struct */
|
/* try to allocate our return struct */
|
||||||
if ((ret = malloc(info->npossible * sizeof(Ecore_X_Randr_Output))))
|
if ((ret = malloc(info->npossible * sizeof(Ecore_X_Randr_Output))))
|
||||||
{
|
{
|
||||||
|
@ -1803,6 +1843,11 @@ ecore_x_randr_output_modes_get(Ecore_X_Window root, Ecore_X_Randr_Output output,
|
||||||
|
|
||||||
/* try to get output info */
|
/* try to get output info */
|
||||||
if ((info = XRRGetOutputInfo(_ecore_x_disp, res, output)))
|
if ((info = XRRGetOutputInfo(_ecore_x_disp, res, output)))
|
||||||
|
{
|
||||||
|
if (num) *num = info->nmode;
|
||||||
|
if (npreferred) *npreferred = info->npreferred;
|
||||||
|
|
||||||
|
if (info->nmode > 0)
|
||||||
{
|
{
|
||||||
if ((modes = malloc(info->nmode * sizeof(Ecore_X_Randr_Mode))))
|
if ((modes = malloc(info->nmode * sizeof(Ecore_X_Randr_Mode))))
|
||||||
{
|
{
|
||||||
|
@ -1810,9 +1855,7 @@ ecore_x_randr_output_modes_get(Ecore_X_Window root, Ecore_X_Randr_Output output,
|
||||||
|
|
||||||
for (i = 0; i < info->nmode; i++)
|
for (i = 0; i < info->nmode; i++)
|
||||||
modes[i] = info->modes[i];
|
modes[i] = info->modes[i];
|
||||||
|
}
|
||||||
if (num) *num = info->nmode;
|
|
||||||
if (npreferred) *npreferred = info->npreferred;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free the output info */
|
/* free the output info */
|
||||||
|
@ -1851,6 +1894,10 @@ ecore_x_randr_output_clones_get(Ecore_X_Window root, Ecore_X_Randr_Output output
|
||||||
|
|
||||||
/* try to get output info */
|
/* try to get output info */
|
||||||
if ((info = XRRGetOutputInfo(_ecore_x_disp, res, output)))
|
if ((info = XRRGetOutputInfo(_ecore_x_disp, res, output)))
|
||||||
|
{
|
||||||
|
if (num) *num = info->nclone;
|
||||||
|
|
||||||
|
if (info->nclone > 0)
|
||||||
{
|
{
|
||||||
/* try to allocate space for output return */
|
/* try to allocate space for output return */
|
||||||
if ((outputs = malloc(info->nclone * sizeof(Ecore_X_Randr_Output))))
|
if ((outputs = malloc(info->nclone * sizeof(Ecore_X_Randr_Output))))
|
||||||
|
@ -1859,8 +1906,7 @@ ecore_x_randr_output_clones_get(Ecore_X_Window root, Ecore_X_Randr_Output output
|
||||||
|
|
||||||
for (i = 0; i < info->nclone; i++)
|
for (i = 0; i < info->nclone; i++)
|
||||||
outputs[i] = info->clones[i];
|
outputs[i] = info->clones[i];
|
||||||
|
}
|
||||||
if (num) *num = info->nclone;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free the output info */
|
/* free the output info */
|
||||||
|
@ -1892,6 +1938,10 @@ ecore_x_randr_output_possible_crtcs_get(Ecore_X_Window root, Ecore_X_Randr_Outpu
|
||||||
|
|
||||||
/* try to get output info */
|
/* try to get output info */
|
||||||
if ((info = XRRGetOutputInfo(_ecore_x_disp, res, output)))
|
if ((info = XRRGetOutputInfo(_ecore_x_disp, res, output)))
|
||||||
|
{
|
||||||
|
if (num) *num = info->ncrtc;
|
||||||
|
|
||||||
|
if (info->ncrtc > 0)
|
||||||
{
|
{
|
||||||
/* try to allocate space for the return crtcs */
|
/* try to allocate space for the return crtcs */
|
||||||
if ((crtcs = malloc(info->ncrtc * sizeof(Ecore_X_Randr_Crtc))))
|
if ((crtcs = malloc(info->ncrtc * sizeof(Ecore_X_Randr_Crtc))))
|
||||||
|
@ -1900,8 +1950,7 @@ ecore_x_randr_output_possible_crtcs_get(Ecore_X_Window root, Ecore_X_Randr_Outpu
|
||||||
|
|
||||||
for (i = 0; i < info->ncrtc; i++)
|
for (i = 0; i < info->ncrtc; i++)
|
||||||
crtcs[i] = info->crtcs[i];
|
crtcs[i] = info->crtcs[i];
|
||||||
|
}
|
||||||
if (num) *num = info->ncrtc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free the output info */
|
/* free the output info */
|
||||||
|
@ -2103,7 +2152,8 @@ ecore_x_randr_move_all_crtcs_but(Ecore_X_Window root, const Ecore_X_Randr_Crtc *
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
n = (res->ncrtc - nnot_moved);
|
n = (res->ncrtc - nnot_moved);
|
||||||
|
if (n > 0)
|
||||||
|
{
|
||||||
/* try to allocate space for a list of crtcs */
|
/* try to allocate space for a list of crtcs */
|
||||||
if ((crtcs = malloc(n * sizeof(Ecore_X_Randr_Crtc))))
|
if ((crtcs = malloc(n * sizeof(Ecore_X_Randr_Crtc))))
|
||||||
{
|
{
|
||||||
|
@ -2120,13 +2170,17 @@ ecore_x_randr_move_all_crtcs_but(Ecore_X_Window root, const Ecore_X_Randr_Crtc *
|
||||||
if (j == nnot_moved) crtcs[k++] = res->crtcs[i];
|
if (j == nnot_moved) crtcs[k++] = res->crtcs[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* free the resources */
|
/* free the resources */
|
||||||
XRRFreeScreenResources(res);
|
XRRFreeScreenResources(res);
|
||||||
|
|
||||||
/* actually move the crtcs */
|
/* actually move the crtcs */
|
||||||
|
if (crtcs)
|
||||||
|
{
|
||||||
ret = ecore_x_randr_move_crtcs(root, crtcs, n, dx, dy);
|
ret = ecore_x_randr_move_crtcs(root, crtcs, n, dx, dy);
|
||||||
free(crtcs);
|
free(crtcs);
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -2156,6 +2210,8 @@ ecore_x_randr_move_crtcs(Ecore_X_Window root, const Ecore_X_Randr_Crtc *crtcs, i
|
||||||
|
|
||||||
if (_randr_version < RANDR_VERSION_1_2) return EINA_FALSE;
|
if (_randr_version < RANDR_VERSION_1_2) return EINA_FALSE;
|
||||||
|
|
||||||
|
if (ncrtc < 1) return EINA_FALSE;
|
||||||
|
|
||||||
/* try to get the screen resources from Xrandr */
|
/* try to get the screen resources from Xrandr */
|
||||||
if ((res = _ecore_x_randr_screen_resources_get(_ecore_x_disp, root)))
|
if ((res = _ecore_x_randr_screen_resources_get(_ecore_x_disp, root)))
|
||||||
{
|
{
|
||||||
|
@ -2559,7 +2615,7 @@ ecore_x_randr_output_edid_get(Ecore_X_Window root EINA_UNUSED, Ecore_X_Randr_Out
|
||||||
AnyPropertyType, &type, &format, &nitems,
|
AnyPropertyType, &type, &format, &nitems,
|
||||||
&bytes, &prop))
|
&bytes, &prop))
|
||||||
{
|
{
|
||||||
if ((type == XA_INTEGER) && (format == 8))
|
if ((type == XA_INTEGER) && (nitems >= 1) && (format == 8))
|
||||||
{
|
{
|
||||||
unsigned char *ret = NULL;
|
unsigned char *ret = NULL;
|
||||||
|
|
||||||
|
@ -2702,13 +2758,17 @@ ecore_x_randr_output_signal_formats_get(Ecore_X_Window root EINA_UNUSED, Ecore_X
|
||||||
{
|
{
|
||||||
Ecore_X_Randr_Signal_Format *formats = NULL;
|
Ecore_X_Randr_Signal_Format *formats = NULL;
|
||||||
|
|
||||||
|
if (num) *num = info->num_values;
|
||||||
|
|
||||||
|
if (info->num_values > 0)
|
||||||
|
{
|
||||||
if ((formats =
|
if ((formats =
|
||||||
malloc(info->num_values * sizeof(Ecore_X_Randr_Signal_Format))))
|
malloc(info->num_values * sizeof(Ecore_X_Randr_Signal_Format))))
|
||||||
{
|
{
|
||||||
if (num) *num = info->num_values;
|
|
||||||
memcpy(formats, info->values,
|
memcpy(formats, info->values,
|
||||||
(info->num_values * sizeof(Ecore_X_Randr_Signal_Format)));
|
(info->num_values * sizeof(Ecore_X_Randr_Signal_Format)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* free the info */
|
/* free the info */
|
||||||
free(info);
|
free(info);
|
||||||
|
@ -2766,13 +2826,17 @@ ecore_x_randr_output_signal_properties_get(Ecore_X_Window root EINA_UNUSED, Ecor
|
||||||
{
|
{
|
||||||
Ecore_X_Randr_Signal_Property *props = NULL;
|
Ecore_X_Randr_Signal_Property *props = NULL;
|
||||||
|
|
||||||
|
if (num) *num = info->num_values;
|
||||||
|
|
||||||
|
if (info->num_values > 0)
|
||||||
|
{
|
||||||
if ((props =
|
if ((props =
|
||||||
malloc(info->num_values * sizeof(Ecore_X_Randr_Signal_Property))))
|
malloc(info->num_values * sizeof(Ecore_X_Randr_Signal_Property))))
|
||||||
{
|
{
|
||||||
if (num) *num = info->num_values;
|
|
||||||
memcpy(props, info->values,
|
memcpy(props, info->values,
|
||||||
(info->num_values * sizeof(Ecore_X_Randr_Signal_Property)));
|
(info->num_values * sizeof(Ecore_X_Randr_Signal_Property)));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* free the info */
|
/* free the info */
|
||||||
free(info);
|
free(info);
|
||||||
|
|
Loading…
Reference in New Issue