diff options
author | Alan Coopersmith <alan.coopersmith@oracle.com> | 2010-11-27 22:38:27 -0800 |
---|---|---|
committer | Alan Coopersmith <alan.coopersmith@oracle.com> | 2010-12-07 11:10:35 -0800 |
commit | 3a9bb93dd178084f4ff1abcea331ca5a62f88ce6 (patch) | |
tree | e82a82126bb89c4cb1956a531f8d10e0a88f030f /hw | |
parent | 2416255f7e3fd9190a9e01bda57c992932de4bd9 (diff) |
Convert alloc+sprintf pairs into asprintf() & XNFasprintf() calls
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Mikhail Gusarov <dottedmag@dottedmag.net>
Diffstat (limited to 'hw')
-rw-r--r-- | hw/xfree86/common/xf86Configure.c | 33 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Helper.c | 5 | ||||
-rw-r--r-- | hw/xfree86/common/xf86Init.c | 3 | ||||
-rw-r--r-- | hw/xfree86/common/xf86ShowOpts.c | 3 | ||||
-rw-r--r-- | hw/xfree86/common/xf86pciBus.c | 4 | ||||
-rw-r--r-- | hw/xfree86/common/xf86sbusBus.c | 6 | ||||
-rw-r--r-- | hw/xfree86/dri/dri.c | 7 | ||||
-rw-r--r-- | hw/xfree86/loader/loadmod.c | 12 | ||||
-rw-r--r-- | hw/xfree86/vbe/vbeModes.c | 4 |
9 files changed, 30 insertions, 47 deletions
diff --git a/hw/xfree86/common/xf86Configure.c b/hw/xfree86/common/xf86Configure.c index 7235c6175..b89f70161 100644 --- a/hw/xfree86/common/xf86Configure.c +++ b/hw/xfree86/common/xf86Configure.c @@ -205,12 +205,9 @@ configureScreenSection (int screennum) int depths[] = { 1, 4, 8, 15, 16, 24/*, 32*/ }; parsePrologue (XF86ConfScreenPtr, XF86ConfScreenRec) - ptr->scrn_identifier = malloc(18); - sprintf(ptr->scrn_identifier, "Screen%d", screennum); - ptr->scrn_monitor_str = malloc(19); - sprintf(ptr->scrn_monitor_str, "Monitor%d", screennum); - ptr->scrn_device_str = malloc(16); - sprintf(ptr->scrn_device_str, "Card%d", screennum); + XNFasprintf(&ptr->scrn_identifier, "Screen%d", screennum); + XNFasprintf(&ptr->scrn_monitor_str, "Monitor%d", screennum); + XNFasprintf(&ptr->scrn_device_str, "Card%d", screennum); for (i=0; i<sizeof(depths)/sizeof(depths[0]); i++) { @@ -256,14 +253,13 @@ optionTypeToString(OptionValueType type) static XF86ConfDevicePtr configureDeviceSection (int screennum) { - char identifier[16]; OptionInfoPtr p; int i = 0; parsePrologue (XF86ConfDevicePtr, XF86ConfDeviceRec) /* Move device info to parser structure */ - sprintf(identifier, "Card%d", screennum); - ptr->dev_identifier = strdup(identifier); + if (asprintf(&ptr->dev_identifier, "Card%d", screennum) == -1) + ptr->dev_identifier = NULL; ptr->dev_chipset = DevToConfig[screennum].GDev.chipset; ptr->dev_busid = DevToConfig[screennum].GDev.busID; ptr->dev_driver = DevToConfig[screennum].GDev.driver; @@ -306,10 +302,8 @@ configureDeviceSection (int screennum) int len = strlen(ptr->dev_comment) + strlen(prefix) + strlen(middle) + strlen(suffix) + 1; - optname = malloc(strlen(p->name) + 2 + 1); - if (!optname) + if (asprintf(&optname, "\"%s\"", p->name) == -1) break; - sprintf(optname, "\"%s\"", p->name); len += max(20, strlen(optname)); len += strlen(opttype); @@ -370,16 +364,14 @@ configureLayoutSection (void) aptr->adj_x = 0; aptr->adj_y = 0; aptr->adj_scrnum = scrnum; - aptr->adj_screen_str = xnfalloc(18); - sprintf(aptr->adj_screen_str, "Screen%d", scrnum); + XNFasprintf(&aptr->adj_screen_str, "Screen%d", scrnum); if (scrnum == 0) { aptr->adj_where = CONF_ADJ_ABSOLUTE; aptr->adj_refscreen = NULL; } else { aptr->adj_where = CONF_ADJ_RIGHTOF; - aptr->adj_refscreen = xnfalloc(18); - sprintf(aptr->adj_refscreen, "Screen%d", scrnum - 1); + XNFasprintf(&aptr->adj_refscreen, "Screen%d", scrnum - 1); } ptr->lay_adjacency_lst = (XF86ConfAdjacencyPtr)xf86addListItem((glp)ptr->lay_adjacency_lst, @@ -443,8 +435,7 @@ configureMonitorSection (int screennum) { parsePrologue (XF86ConfMonitorPtr, XF86ConfMonitorRec) - ptr->mon_identifier = malloc(19); - sprintf(ptr->mon_identifier, "Monitor%d", screennum); + XNFasprintf(&ptr->mon_identifier, "Monitor%d", screennum); ptr->mon_vendor = strdup("Monitor Vendor"); ptr->mon_modelname = strdup("Monitor Model"); @@ -491,11 +482,9 @@ configureDDCMonitorSection (int screennum) parsePrologue (XF86ConfMonitorPtr, XF86ConfMonitorRec) - ptr->mon_identifier = malloc(19); - sprintf(ptr->mon_identifier, "Monitor%d", screennum); + XNFasprintf(&ptr->mon_identifier, "Monitor%d", screennum); ptr->mon_vendor = strdup(ConfiguredMonitor->vendor.name); - ptr->mon_modelname = malloc(12); - sprintf(ptr->mon_modelname, "%x", ConfiguredMonitor->vendor.prod_id); + XNFasprintf(&ptr->mon_modelname, "%x", ConfiguredMonitor->vendor.prod_id); /* features in centimetres, we want millimetres */ mon_width = 10 * ConfiguredMonitor->features.hsize ; diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c index ce144544b..9e2ffaace 100644 --- a/hw/xfree86/common/xf86Helper.c +++ b/hw/xfree86/common/xf86Helper.c @@ -1284,11 +1284,8 @@ xf86LogInit(void) /* Get the log file name */ if (xf86LogFileFrom == X_DEFAULT) { /* Append the display number and ".log" */ - lf = malloc(strlen(xf86LogFile) + strlen("%s") + - strlen(LOGSUFFIX) + 1); - if (!lf) + if (asprintf(&lf, "%s%%s" LOGSUFFIX, xf86LogFile) == -1) FatalError("Cannot allocate space for the log file name\n"); - sprintf(lf, "%s%%s" LOGSUFFIX, xf86LogFile); xf86LogFile = lf; } diff --git a/hw/xfree86/common/xf86Init.c b/hw/xfree86/common/xf86Init.c index ef90fa51c..78f51e166 100644 --- a/hw/xfree86/common/xf86Init.c +++ b/hw/xfree86/common/xf86Init.c @@ -536,8 +536,7 @@ InitOutput(ScreenInfo *pScreenInfo, int argc, char **argv) for (i = 0; i < xf86NumScreens; i++) { if (xf86Screens[i]->name == NULL) { - xf86Screens[i]->name = xnfalloc(strlen("screen") + 10 + 1); - sprintf(xf86Screens[i]->name, "screen%d", i); + XNFasprintf(&xf86Screens[i]->name, "screen%d", i); xf86MsgVerb(X_WARNING, 0, "Screen driver %d has no name set, using `%s'.\n", i, xf86Screens[i]->name); diff --git a/hw/xfree86/common/xf86ShowOpts.c b/hw/xfree86/common/xf86ShowOpts.c index eac25d701..ce8609081 100644 --- a/hw/xfree86/common/xf86ShowOpts.c +++ b/hw/xfree86/common/xf86ShowOpts.c @@ -111,6 +111,9 @@ void DoShowOptions (void) { ); for (p = pOption; p->name != NULL; p++) { const char *opttype = optionTypeToSting(p->type); + /* XXX: Why overallocate by 2 bytes? + * Otherwise, this would be strdup() + */ char *optname = malloc(strlen(p->name) + 2 + 1); if (!optname) { continue; diff --git a/hw/xfree86/common/xf86pciBus.c b/hw/xfree86/common/xf86pciBus.c index d6898322e..447b19229 100644 --- a/hw/xfree86/common/xf86pciBus.c +++ b/hw/xfree86/common/xf86pciBus.c @@ -1347,9 +1347,9 @@ xf86PciConfigureNewDev(void *busData, struct pci_device *pVideo, pVideo = (struct pci_device *) busData; - GDev->busID = xnfalloc(16); xf86FormatPciBusNumber(pVideo->bus, busnum); - sprintf(GDev->busID, "PCI:%s:%d:%d", busnum, pVideo->dev, pVideo->func); + XNFasprintf(&GDev->busID, "PCI:%s:%d:%d", + busnum, pVideo->dev, pVideo->func); GDev->chipID = pVideo->device_id; GDev->chipRev = pVideo->revision; diff --git a/hw/xfree86/common/xf86sbusBus.c b/hw/xfree86/common/xf86sbusBus.c index d7c928b4c..8cfac84e0 100644 --- a/hw/xfree86/common/xf86sbusBus.c +++ b/hw/xfree86/common/xf86sbusBus.c @@ -706,11 +706,9 @@ xf86SbusConfigureNewDev(void *busData, sbusDevicePtr sBus, GDevRec *GDev) sparcPromClose(); } if (promPath) { - GDev->busID = xnfalloc(strlen(promPath) + 6); - sprintf(GDev->busID, "SBUS:%s", promPath); + XNFasprintf(&GDev->busID, "SBUS:%s", promPath); free(promPath); } else { - GDev->busID = xnfalloc(12); - sprintf(GDev->busID, "SBUS:fb%d", sBus->fbNum); + XNFsprintf(&GDev->busID, "SBUS:fb%d", sBus->fbNum); } } diff --git a/hw/xfree86/dri/dri.c b/hw/xfree86/dri/dri.c index fe99a2dcc..1d83630a5 100644 --- a/hw/xfree86/dri/dri.c +++ b/hw/xfree86/dri/dri.c @@ -2426,13 +2426,10 @@ DRICreatePCIBusID(const struct pci_device * dev) { char *busID; - busID = malloc(20); - if (busID == NULL) + if (asprintf(&busID, "pci:%04x:%02x:%02x.%d", + dev->domain, dev->bus, dev->dev, dev->func) == -1) return NULL; - snprintf(busID, 20, "pci:%04x:%02x:%02x.%d", dev->domain, dev->bus, - dev->dev, dev->func); - return busID; } diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c index 06d082b34..1f6933a3b 100644 --- a/hw/xfree86/loader/loadmod.c +++ b/hw/xfree86/loader/loadmod.c @@ -406,22 +406,22 @@ FindModuleInSubdir(const char *dirpath, const char *module) snprintf(tmpBuf, PATH_MAX, "lib%s.so", module); if (strcmp(direntry->d_name, tmpBuf) == 0) { - ret = malloc(strlen(tmpBuf) + strlen(dirpath) + 1); - sprintf(ret, "%s%s", dirpath, tmpBuf); + if (asprintf(&ret, "%s%s", dirpath, tmpBuf) == -1) + ret = NULL; break; } snprintf(tmpBuf, PATH_MAX, "%s_drv.so", module); if (strcmp(direntry->d_name, tmpBuf) == 0) { - ret = malloc(strlen(tmpBuf) + strlen(dirpath) + 1); - sprintf(ret, "%s%s", dirpath, tmpBuf); + if (asprintf(&ret, "%s%s", dirpath, tmpBuf) == -1) + ret = NULL; break; } snprintf(tmpBuf, PATH_MAX, "%s.so", module); if (strcmp(direntry->d_name, tmpBuf) == 0) { - ret = malloc(strlen(tmpBuf) + strlen(dirpath) + 1); - sprintf(ret, "%s%s", dirpath, tmpBuf); + if (asprintf(&ret, "%s%s", dirpath, tmpBuf) == -1) + ret = NULL; break; } } diff --git a/hw/xfree86/vbe/vbeModes.c b/hw/xfree86/vbe/vbeModes.c index 3f2cae5bf..ea24b61cd 100644 --- a/hw/xfree86/vbe/vbeModes.c +++ b/hw/xfree86/vbe/vbeModes.c @@ -356,8 +356,8 @@ VBESetModeNames(DisplayModePtr pMode) pMode->VDisplay > 10000 || pMode->VDisplay < 0) { pMode->name = strdup("BADMODE"); } else { - pMode->name = xnfalloc(4 + 1 + 4 + 1); - sprintf(pMode->name, "%dx%d", pMode->HDisplay, pMode->VDisplay); + XNFasprintf(&pMode->name, "%dx%d", + pMode->HDisplay, pMode->VDisplay); } } pMode = pMode->next; |