Skip to content

Commit 9b3f59a

Browse files
committed
[PR #1353] xfree86: common: replace XNFasprintf() by standard libc asprintf()
PR: #1353
1 parent d5e3375 commit 9b3f59a

File tree

5 files changed

+37
-22
lines changed

5 files changed

+37
-22
lines changed

hw/xfree86/common/xf86Config.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,10 @@ xf86ValidateFontPath(char *path)
202202
continue;
203203
}
204204
else {
205-
XNFasprintf(&p1, "%s%s", dir_elem, DIR_FILE);
205+
if (asprintf(&p1, "%s%s", dir_elem, DIR_FILE) == -1) {
206+
xf86ErrorF("malloc failed\n");
207+
continue;
208+
}
206209
flag = stat(p1, &stat_buf);
207210
if (flag == 0)
208211
if (!S_ISREG(stat_buf.st_mode))

hw/xfree86/common/xf86Configure.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,17 @@ configureScreenSection(int screennum)
205205
{
206206
int i;
207207
int depths[] = { 1, 4, 8, 15, 16, 24 /*, 32 */ };
208-
char *tmp;
208+
char *tmp = NULL;
209209
parsePrologue(XF86ConfScreenPtr, XF86ConfScreenRec);
210210

211-
XNFasprintf(&tmp, "Screen%d", screennum);
211+
if (asprintf(&tmp, "Screen%d", screennum) == -1)
212+
return NULL;
212213
ptr->scrn_identifier = tmp;
213-
XNFasprintf(&tmp, "Monitor%d", screennum);
214+
if (asprintf(&tmp, "Monitor%d", screennum) == -1)
215+
return NULL;
214216
ptr->scrn_monitor_str = tmp;
215-
XNFasprintf(&tmp, "Card%d", screennum);
217+
if (asprintf(&tmp, "Card%d", screennum) == -1)
218+
return NULL;
216219
ptr->scrn_device_str = tmp;
217220

218221
for (i = 0; i < ARRAY_SIZE(depths); i++) {
@@ -368,23 +371,24 @@ configureLayoutSection(void)
368371
}
369372

370373
for (scrnum = 0; scrnum < nDevToConfig; scrnum++) {
371-
char *tmp;
374+
char *tmp = NULL;
372375

373376
XF86ConfAdjacencyPtr aptr = calloc(1, sizeof(XF86ConfAdjacencyRec));
374377
assert(aptr);
375378
aptr->list.next = NULL;
376379
aptr->adj_x = 0;
377380
aptr->adj_y = 0;
378381
aptr->adj_scrnum = scrnum;
379-
XNFasprintf(&tmp, "Screen%d", scrnum);
382+
asprintf(&tmp, "Screen%d", scrnum);
380383
aptr->adj_screen_str = tmp;
381384
if (scrnum == 0) {
382385
aptr->adj_where = CONF_ADJ_ABSOLUTE;
383386
aptr->adj_refscreen = NULL;
384387
}
385388
else {
386389
aptr->adj_where = CONF_ADJ_RIGHTOF;
387-
XNFasprintf(&tmp, "Screen%d", scrnum - 1);
390+
tmp == NULL;
391+
asprintf(&tmp, "Screen%d", scrnum - 1);
388392
aptr->adj_refscreen = tmp;
389393
}
390394
ptr->lay_adjacency_lst =
@@ -443,10 +447,11 @@ configureFilesSection(void)
443447
static XF86ConfMonitorPtr
444448
configureMonitorSection(int screennum)
445449
{
446-
char *tmp;
450+
char *tmp = NULL;
447451
parsePrologue(XF86ConfMonitorPtr, XF86ConfMonitorRec);
448452

449-
XNFasprintf(&tmp, "Monitor%d", screennum);
453+
if (asprintf(&tmp, "Monitor%d", screennum) == -1)
454+
return NULL;
450455
ptr->mon_identifier = tmp;
451456
ptr->mon_vendor = XNFstrdup("Monitor Vendor");
452457
ptr->mon_modelname = XNFstrdup("Monitor Model");
@@ -492,10 +497,12 @@ configureDDCMonitorSection(int screennum)
492497

493498
parsePrologue(XF86ConfMonitorPtr, XF86ConfMonitorRec);
494499

495-
XNFasprintf(&tmp, "Monitor%d", screennum);
500+
if (asprintf(&tmp, "Monitor%d", screennum) == -1)
501+
return NULL;
496502
ptr->mon_identifier = tmp;
497503
ptr->mon_vendor = XNFstrdup(ConfiguredMonitor->vendor.name);
498-
XNFasprintf(&ptr->mon_modelname, "%x", ConfiguredMonitor->vendor.prod_id);
504+
if (asprintf(&ptr->mon_modelname, "%x", ConfiguredMonitor->vendor.prod_id) == -1)
505+
FatalError("malloc failed\n");
499506

500507
/* features in centimetres, we want millimetres */
501508
mon_width = 10 * ConfiguredMonitor->features.hsize;
@@ -866,8 +873,11 @@ DoShowOptions(void)
866873
xf86DriverList[i]->driverName);
867874
continue;
868875
}
869-
XNFasprintf(&pSymbol, "%sModuleData",
870-
xf86DriverList[i]->driverName);
876+
if (asprintf(&pSymbol, "%sModuleData",
877+
xf86DriverList[i]->driverName) == -1) {
878+
ErrorF("(EE) malloc failed\n");
879+
continue;
880+
}
871881
initData = LoaderSymbol(pSymbol);
872882
if (initData) {
873883
XF86ModuleVersionInfo *vers = initData->vers;

hw/xfree86/common/xf86pciBus.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,14 +1444,15 @@ xf86PciConfigureNewDev(void *busData, struct pci_device *pVideo,
14441444
GDevRec * GDev, int *chipset)
14451445
{
14461446
char busnum[8];
1447-
char *tmp;
1447+
char *tmp = NULL;
14481448

14491449
pVideo = (struct pci_device *) busData;
14501450

14511451
snprintf(busnum, sizeof(busnum), "%d", pVideo->bus);
14521452

1453-
XNFasprintf(&tmp, "PCI:%s:%d:%d",
1454-
busnum, pVideo->dev, pVideo->func);
1453+
if (asprintf(&tmp, "PCI:%s:%d:%d",
1454+
busnum, pVideo->dev, pVideo->func) == -1)
1455+
FatalError("malloc failed\n");
14551456
GDev->busID = tmp;
14561457

14571458
GDev->chipID = pVideo->device_id;

hw/xfree86/common/xf86platformBus.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,9 @@ xf86platformProbe(void)
286286

287287
if (cl->modulepath && xf86ModPathFrom != X_CMDLINE) {
288288
old_path = path;
289-
XNFasprintf(&path, "%s,%s", cl->modulepath,
290-
path ? path : xf86ModulePath);
289+
if (asprintf(&path, "%s,%s", cl->modulepath,
290+
path ? path : xf86ModulePath) == -1)
291+
FatalError("malloc failed\n");
291292
free(old_path);
292293
LogMessageVerb(X_CONFIG, 1, "OutputClass \"%s\" ModulePath extended to \"%s\"\n",
293294
cl->identifier, path);

hw/xfree86/common/xf86sbusBus.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ void
717717
xf86SbusConfigureNewDev(void *busData, sbusDevicePtr sBus, GDevRec * GDev)
718718
{
719719
char *promPath = NULL;
720-
char *tmp;
720+
char *tmp = NULL;
721721

722722
sBus = (sbusDevicePtr) busData;
723723
GDev->identifier = sBus->descr;
@@ -726,11 +726,11 @@ xf86SbusConfigureNewDev(void *busData, sbusDevicePtr sBus, GDevRec * GDev)
726726
sparcPromClose();
727727
}
728728
if (promPath) {
729-
XNFasprintf(&tmp, "SBUS:%s", promPath);
729+
asprintf(&tmp, "SBUS:%s", promPath);
730730
free(promPath);
731731
}
732732
else {
733-
XNFasprintf(&tmp, "SBUS:fb%d", sBus->fbNum);
733+
asprintf(&tmp, "SBUS:fb%d", sBus->fbNum);
734734
}
735735
GDev->busID = tmp;
736736
}

0 commit comments

Comments
 (0)