Convert xf86FindPrimaryDevice to use a static buffer and snprintf.
Rather than allocate a 9 byte buffer on each invocation, use a static 16 byte buffer. Use snprintf for safety. This commit should probably be cherry-picked to the trunk.
This commit is contained in:
		
							parent
							
								
									28976bebec
								
							
						
					
					
						commit
						d2f8c42c48
					
				| 
						 | 
				
			
			@ -2983,14 +2983,15 @@ xf86FindPrimaryDevice()
 | 
			
		|||
        CheckGenericGA();
 | 
			
		||||
    if (primaryBus.type != BUS_NONE) {
 | 
			
		||||
	char *bus;
 | 
			
		||||
	char *loc = xnfcalloc(1,9);
 | 
			
		||||
	if (loc == NULL) return;
 | 
			
		||||
	char loc[16];
 | 
			
		||||
 | 
			
		||||
	switch (primaryBus.type) {
 | 
			
		||||
	case BUS_PCI:
 | 
			
		||||
	    bus = "PCI";
 | 
			
		||||
	    sprintf(loc," %2.2x:%2.2x:%1.1x",primaryBus.id.pci.bus,
 | 
			
		||||
	    primaryBus.id.pci.device,primaryBus.id.pci.func);
 | 
			
		||||
	    snprintf(loc, sizeof(loc), " %2.2x:%2.2x:%1.1x",
 | 
			
		||||
		     primaryBus.id.pci.bus,
 | 
			
		||||
		     primaryBus.id.pci.device,
 | 
			
		||||
		     primaryBus.id.pci.func);
 | 
			
		||||
	    break;
 | 
			
		||||
	case BUS_ISA:
 | 
			
		||||
	    bus = "ISA";
 | 
			
		||||
| 
						 | 
				
			
			@ -2998,17 +2999,15 @@ xf86FindPrimaryDevice()
 | 
			
		|||
	    break;
 | 
			
		||||
	case BUS_SBUS:
 | 
			
		||||
	    bus = "SBUS";
 | 
			
		||||
	    sprintf(loc," %2.2x",primaryBus.id.sbus.fbNum);
 | 
			
		||||
	    snprintf(loc, sizeof(loc), " %2.2x", primaryBus.id.sbus.fbNum);
 | 
			
		||||
	    break;
 | 
			
		||||
	default:
 | 
			
		||||
	    bus = "";
 | 
			
		||||
	    loc[0] = '\0';
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	xf86MsgVerb(X_INFO, 2, "Primary Device is: %s%s\n",bus,loc);
 | 
			
		||||
	xfree(loc);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if !defined(__sparc) && !defined(__sparc__) && !defined(__powerpc__) && !defined(__mips__)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue