randr: refine allocation and copying of optional buffers
Simplifying the code flow allocating/checking/copying some buffers in RRConfigureOutputProperty() and RRConfigureProviderProperty() so it's easier to understand for both the human reader as well as the analyzer. Depending on whether we have elements to process, a temporary buffer needs to be allocated, checked for successful allocation and copy over data. The way it's currently done is technically correct, but unnecessarily complex to understand: instead of just branching on whether there are elements and doing all the buffer-related things only then, the branching is done just somewhere in the middle, only on checking for allocation failure, and relying on both calloc() and memcpy() not doing weird things when size is zero. It's easy to simplify by putting it all behind one if statement and so make things easier for both human reader as well as the analyzer (so it's not spilling out false alarms here anymore) and also drops unnecessary calls in the zero-size case. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
parent
ed289f734b
commit
5b13d85464
|
@ -360,7 +360,6 @@ RRConfigureOutputProperty(RROutputPtr output, Atom property,
|
||||||
{
|
{
|
||||||
RRPropertyPtr prop = RRQueryOutputProperty(output, property);
|
RRPropertyPtr prop = RRQueryOutputProperty(output, property);
|
||||||
Bool add = FALSE;
|
Bool add = FALSE;
|
||||||
INT32 *new_values;
|
|
||||||
|
|
||||||
if (!prop) {
|
if (!prop) {
|
||||||
prop = RRCreateOutputProperty(property);
|
prop = RRCreateOutputProperty(property);
|
||||||
|
@ -380,14 +379,17 @@ RRConfigureOutputProperty(RROutputPtr output, Atom property,
|
||||||
return BadMatch;
|
return BadMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_values = xallocarray(num_values, sizeof(INT32));
|
INT32 *new_values = NULL;
|
||||||
if (!new_values && num_values) {
|
|
||||||
|
if (num_values) {
|
||||||
|
new_values = calloc(num_values, sizeof(INT32));
|
||||||
|
if (!new_values) {
|
||||||
if (add)
|
if (add)
|
||||||
RRDestroyOutputProperty(prop);
|
RRDestroyOutputProperty(prop);
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
}
|
}
|
||||||
if (num_values)
|
|
||||||
memcpy(new_values, values, num_values * sizeof(INT32));
|
memcpy(new_values, values, num_values * sizeof(INT32));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Property moving from pending to non-pending
|
* Property moving from pending to non-pending
|
||||||
|
|
|
@ -277,7 +277,6 @@ RRConfigureProviderProperty(RRProviderPtr provider, Atom property,
|
||||||
{
|
{
|
||||||
RRPropertyPtr prop = RRQueryProviderProperty(provider, property);
|
RRPropertyPtr prop = RRQueryProviderProperty(provider, property);
|
||||||
Bool add = FALSE;
|
Bool add = FALSE;
|
||||||
INT32 *new_values;
|
|
||||||
|
|
||||||
if (!prop) {
|
if (!prop) {
|
||||||
prop = RRCreateProviderProperty(property);
|
prop = RRCreateProviderProperty(property);
|
||||||
|
@ -297,14 +296,16 @@ RRConfigureProviderProperty(RRProviderPtr provider, Atom property,
|
||||||
return BadMatch;
|
return BadMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
new_values = xallocarray(num_values, sizeof(INT32));
|
INT32 *new_values = NULL;
|
||||||
if (!new_values && num_values) {
|
if (num_values) {
|
||||||
|
new_values = calloc(num_values, sizeof(INT32));
|
||||||
|
if (!new_values) {
|
||||||
if (add)
|
if (add)
|
||||||
RRDestroyProviderProperty(prop);
|
RRDestroyProviderProperty(prop);
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
}
|
}
|
||||||
if (num_values)
|
|
||||||
memcpy(new_values, values, num_values * sizeof(INT32));
|
memcpy(new_values, values, num_values * sizeof(INT32));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Property moving from pending to non-pending
|
* Property moving from pending to non-pending
|
||||||
|
|
Loading…
Reference in New Issue