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:
Ian Romanick 2007-01-17 12:59:17 -08:00
parent 28976bebec
commit d2f8c42c48

View File

@ -2983,14 +2983,15 @@ xf86FindPrimaryDevice()
CheckGenericGA(); CheckGenericGA();
if (primaryBus.type != BUS_NONE) { if (primaryBus.type != BUS_NONE) {
char *bus; char *bus;
char *loc = xnfcalloc(1,9); char loc[16];
if (loc == NULL) return;
switch (primaryBus.type) { switch (primaryBus.type) {
case BUS_PCI: case BUS_PCI:
bus = "PCI"; bus = "PCI";
sprintf(loc," %2.2x:%2.2x:%1.1x",primaryBus.id.pci.bus, snprintf(loc, sizeof(loc), " %2.2x:%2.2x:%1.1x",
primaryBus.id.pci.device,primaryBus.id.pci.func); primaryBus.id.pci.bus,
primaryBus.id.pci.device,
primaryBus.id.pci.func);
break; break;
case BUS_ISA: case BUS_ISA:
bus = "ISA"; bus = "ISA";
@ -2998,17 +2999,15 @@ xf86FindPrimaryDevice()
break; break;
case BUS_SBUS: case BUS_SBUS:
bus = "SBUS"; bus = "SBUS";
sprintf(loc," %2.2x",primaryBus.id.sbus.fbNum); snprintf(loc, sizeof(loc), " %2.2x", primaryBus.id.sbus.fbNum);
break; break;
default: default:
bus = ""; bus = "";
loc[0] = '\0'; loc[0] = '\0';
} }
xf86MsgVerb(X_INFO, 2, "Primary Device is: %s%s\n",bus,loc); xf86MsgVerb(X_INFO, 2, "Primary Device is: %s%s\n",bus,loc);
xfree(loc);
} }
} }
#if !defined(__sparc) && !defined(__sparc__) && !defined(__powerpc__) && !defined(__mips__) #if !defined(__sparc) && !defined(__sparc__) && !defined(__powerpc__) && !defined(__mips__)