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

View File

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

View File

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

View File

@ -97,11 +97,8 @@ void DoShowOptions (void) {
); );
continue; continue;
} }
pSymbol = malloc( XNFasprintf(&pSymbol, "%sModuleData",
strlen(xf86DriverList[i]->driverName) + strlen("ModuleData") + 1 xf86DriverList[i]->driverName);
);
strcpy (pSymbol, xf86DriverList[i]->driverName);
strcat (pSymbol, "ModuleData");
initData = LoaderSymbol (pSymbol); initData = LoaderSymbol (pSymbol);
if (initData) { if (initData) {
XF86ModuleVersionInfo *vers = initData->vers; 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++) { for (i = 0; extensionModules[i].name != NULL; i++) {
if (opts) { if (opts) {
char *s; char *s;
s = (char *)malloc(strlen(extensionModules[i].name) + 5); if (Xasprinf(&s, "omit%s", extensionModules[i].name) != -1) {
if (s) {
pointer o; pointer o;
strcpy(s, "omit");
strcat(s, extensionModules[i].name);
o = xf86FindOption(opts, s); o = xf86FindOption(opts, s);
free(s); free(s);
if (o) { 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 * now check if the special data object <modulename>ModuleData is
* present. * present.
*/ */
p = malloc(strlen(name) + strlen("ModuleData") + 1); if (asprintf(&p, "%sModuleData", name) == -1) {
if (!p) { p = NULL;
if (errmaj) if (errmaj)
*errmaj = LDR_NOMEM; *errmaj = LDR_NOMEM;
if (errmin) if (errmin)
*errmin = 0; *errmin = 0;
goto LoadModule_fail; goto LoadModule_fail;
} }
strcpy(p, name);
strcat(p, "ModuleData");
initdata = LoaderSymbol(p); initdata = LoaderSymbol(p);
if (initdata) { if (initdata) {
ModuleSetupProc setup; ModuleSetupProc setup;

View File

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