(!1972) randr: RROutputSetModes(): simplify buffer allocation / copying
Instead of relying on memcpy() coping with NULL buffer when size == 0, move the call to the branch where we actually have things to copy. This also silences yet another analyzer warning. Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
		
							parent
							
								
									824fe9609f
								
							
						
					
					
						commit
						f608231431
					
				| 
						 | 
					@ -149,7 +149,6 @@ Bool
 | 
				
			||||||
RROutputSetModes(RROutputPtr output,
 | 
					RROutputSetModes(RROutputPtr output,
 | 
				
			||||||
                 RRModePtr * modes, int numModes, int numPreferred)
 | 
					                 RRModePtr * modes, int numModes, int numPreferred)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    RRModePtr *newModes;
 | 
					 | 
				
			||||||
    int i;
 | 
					    int i;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (numModes == output->numModes && numPreferred == output->numPreferred) {
 | 
					    if (numModes == output->numModes && numPreferred == output->numPreferred) {
 | 
				
			||||||
| 
						 | 
					@ -163,19 +162,19 @@ RROutputSetModes(RROutputPtr output,
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    RRModePtr *newModes = NULL;
 | 
				
			||||||
    if (numModes) {
 | 
					    if (numModes) {
 | 
				
			||||||
        newModes = xallocarray(numModes, sizeof(RRModePtr));
 | 
					        newModes = xallocarray(numModes, sizeof(RRModePtr));
 | 
				
			||||||
        if (!newModes)
 | 
					        if (!newModes)
 | 
				
			||||||
            return FALSE;
 | 
					            return FALSE;
 | 
				
			||||||
 | 
					        memcpy(newModes, modes, numModes * sizeof(RRModePtr));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else
 | 
					
 | 
				
			||||||
        newModes = NULL;
 | 
					 | 
				
			||||||
    if (output->modes) {
 | 
					    if (output->modes) {
 | 
				
			||||||
        for (i = 0; i < output->numModes; i++)
 | 
					        for (i = 0; i < output->numModes; i++)
 | 
				
			||||||
            RRModeDestroy(output->modes[i]);
 | 
					            RRModeDestroy(output->modes[i]);
 | 
				
			||||||
        free(output->modes);
 | 
					        free(output->modes);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    memcpy(newModes, modes, numModes * sizeof(RRModePtr));
 | 
					 | 
				
			||||||
    output->modes = newModes;
 | 
					    output->modes = newModes;
 | 
				
			||||||
    output->numModes = numModes;
 | 
					    output->numModes = numModes;
 | 
				
			||||||
    output->numPreferred = numPreferred;
 | 
					    output->numPreferred = numPreferred;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue