Replace alloc+strcpy+strcat with asprintf() & XNFasprintf() calls

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Reviewed-by: Mikhail Gusarov <dottedmag@dottedmag.net>
This commit is contained in:
Alan Coopersmith 2010-11-27 23:10:46 -08:00
parent 3a9bb93dd1
commit d2c42b1027
7 changed files with 20 additions and 32 deletions

View File

@ -2524,9 +2524,11 @@ AllocDevicePair (ClientPtr client, char* name,
if (!pointer)
return BadAlloc;
pointer->name = calloc(strlen(name) + strlen(" pointer") + 1, sizeof(char));
strcpy(pointer->name, name);
strcat(pointer->name, " pointer");
if (asprintf(&pointer->name, "%s pointer", name) == -1) {
pointer->name = NULL;
RemoveDevice(pointer, FALSE);
return BadAlloc;
}
pointer->public.processInputProc = ProcessOtherEvent;
pointer->public.realInputProc = ProcessOtherEvent;
@ -2547,9 +2549,12 @@ AllocDevicePair (ClientPtr client, char* name,
return BadAlloc;
}
keyboard->name = calloc(strlen(name) + strlen(" keyboard") + 1, sizeof(char));
strcpy(keyboard->name, name);
strcat(keyboard->name, " keyboard");
if (asprintf(&keyboard->name, "%s keyboard", name) == -1) {
keyboard->name = NULL;
RemoveDevice(keyboard, FALSE);
RemoveDevice(pointer, FALSE);
return BadAlloc;
}
keyboard->public.processInputProc = ProcessOtherEvent;
keyboard->public.realInputProc = ProcessOtherEvent;

View File

@ -208,9 +208,7 @@ xf86ValidateFontPath(char *path)
continue;
}
else {
p1 = xnfalloc(strlen(dir_elem)+strlen(DIR_FILE)+1);
strcpy(p1, dir_elem);
strcat(p1, DIR_FILE);
XNFasprintf(&p1, "%s%s", dir_elem, DIR_FILE);
flag = stat(p1, &stat_buf);
if (flag == 0)
if (!S_ISREG(stat_buf.st_mode))

View File

@ -638,13 +638,10 @@ ParseOptionValue(int scrnIndex, pointer options, OptionInfoPtr p,
newn = n + 2;
} else {
free(n);
n = malloc(strlen(p->name) + 2 + 1);
if (!n) {
if (asprintf(&n, "No%s", p->name) == -1) {
p->found = FALSE;
return FALSE;
}
strcpy(n, "No");
strcat(n, p->name);
newn = n;
}
if ((s = xf86findOptionValue(options, newn)) != NULL) {

View File

@ -97,11 +97,8 @@ void DoShowOptions (void) {
);
continue;
}
pSymbol = malloc(
strlen(xf86DriverList[i]->driverName) + strlen("ModuleData") + 1
);
strcpy (pSymbol, xf86DriverList[i]->driverName);
strcat (pSymbol, "ModuleData");
XNFasprintf(&pSymbol, "%sModuleData",
xf86DriverList[i]->driverName);
initData = LoaderSymbol (pSymbol);
if (initData) {
XF86ModuleVersionInfo *vers = initData->vers;

View File

@ -146,11 +146,8 @@ extmodSetup(pointer module, pointer opts, int *errmaj, int *errmin)
for (i = 0; extensionModules[i].name != NULL; i++) {
if (opts) {
char *s;
s = (char *)malloc(strlen(extensionModules[i].name) + 5);
if (s) {
if (Xasprinf(&s, "omit%s", extensionModules[i].name) != -1) {
pointer o;
strcpy(s, "omit");
strcat(s, extensionModules[i].name);
o = xf86FindOption(opts, s);
free(s);
if (o) {

View File

@ -933,16 +933,14 @@ doLoadModule(const char *module, const char *path, const char **subdirlist,
* now check if the special data object <modulename>ModuleData is
* present.
*/
p = malloc(strlen(name) + strlen("ModuleData") + 1);
if (!p) {
if (asprintf(&p, "%sModuleData", name) == -1) {
p = NULL;
if (errmaj)
*errmaj = LDR_NOMEM;
if (errmin)
*errmin = 0;
goto LoadModule_fail;
}
strcpy(p, name);
strcat(p, "ModuleData");
initdata = LoaderSymbol(p);
if (initdata) {
ModuleSetupProc setup;

View File

@ -510,7 +510,6 @@ static void
xf86OutputSetMonitor (xf86OutputPtr output)
{
char *option_name;
static const char monitor_prefix[] = "monitor-";
char *monitor;
if (!output->name)
@ -520,11 +519,8 @@ xf86OutputSetMonitor (xf86OutputPtr output)
output->options = xnfalloc (sizeof (xf86OutputOptions));
memcpy (output->options, xf86OutputOptions, sizeof (xf86OutputOptions));
option_name = xnfalloc (strlen (monitor_prefix) +
strlen (output->name) + 1);
strcpy (option_name, monitor_prefix);
strcat (option_name, output->name);
XNFasprintf(&option_name, "monitor-%s", output->name);
monitor = xf86findOptionValue (output->scrn->options, option_name);
if (!monitor)
monitor = output->name;