Replace malloc/strlen/strcpy with strdup.
Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com> Signed-off-by: Matt Turner <mattst88@gmail.com>
This commit is contained in:
parent
ea239112b0
commit
08adf41f63
|
@ -1154,8 +1154,7 @@ void
|
|||
AssignTypeAndName(DeviceIntPtr dev, Atom type, char *name)
|
||||
{
|
||||
dev->xinput_type = type;
|
||||
dev->name = (char *)malloc(strlen(name) + 1);
|
||||
strcpy(dev->name, name);
|
||||
dev->name = strdup(name);
|
||||
}
|
||||
|
||||
/***********************************************************************
|
||||
|
|
|
@ -96,7 +96,7 @@ AddExtension(char *name, int NumEvents, int NumErrors,
|
|||
free(ext);
|
||||
return NULL;
|
||||
}
|
||||
ext->name = malloc(strlen(name) + 1);
|
||||
ext->name = strdup(name);
|
||||
ext->num_aliases = 0;
|
||||
ext->aliases = (char **)NULL;
|
||||
if (!ext->name)
|
||||
|
@ -105,7 +105,6 @@ AddExtension(char *name, int NumEvents, int NumErrors,
|
|||
free(ext);
|
||||
return((ExtensionEntry *) NULL);
|
||||
}
|
||||
strcpy(ext->name, name);
|
||||
i = NumExtensions;
|
||||
newexts = (ExtensionEntry **) realloc(extensions,
|
||||
(i + 1) * sizeof(ExtensionEntry *));
|
||||
|
@ -164,10 +163,9 @@ Bool AddExtensionAlias(char *alias, ExtensionEntry *ext)
|
|||
if (!aliases)
|
||||
return FALSE;
|
||||
ext->aliases = aliases;
|
||||
name = malloc(strlen(alias) + 1);
|
||||
name = strdup(alias);
|
||||
if (!name)
|
||||
return FALSE;
|
||||
strcpy(name, alias);
|
||||
ext->aliases[ext->num_aliases] = name;
|
||||
ext->num_aliases++;
|
||||
return TRUE;
|
||||
|
|
|
@ -377,8 +377,7 @@ KdXVInitAdaptors(
|
|||
pa->ddGetPortAttribute = KdXVGetPortAttribute;
|
||||
pa->ddQueryBestSize = KdXVQueryBestSize;
|
||||
pa->ddQueryImageAttributes = KdXVQueryImageAttributes;
|
||||
if((pa->name = malloc(strlen(adaptorPtr->name) + 1)))
|
||||
strcpy(pa->name, adaptorPtr->name);
|
||||
pa->name = strdup(adaptorPtr->name);
|
||||
|
||||
if(adaptorPtr->nEncodings &&
|
||||
(pEncode = calloc(adaptorPtr->nEncodings, sizeof(XvEncodingRec)))) {
|
||||
|
@ -388,8 +387,7 @@ KdXVInitAdaptors(
|
|||
{
|
||||
pe->id = encodingPtr->id;
|
||||
pe->pScreen = pScreen;
|
||||
if((pe->name = malloc(strlen(encodingPtr->name) + 1)))
|
||||
strcpy(pe->name, encodingPtr->name);
|
||||
pe->name = strdup(encodingPtr->name);
|
||||
pe->width = encodingPtr->width;
|
||||
pe->height = encodingPtr->height;
|
||||
pe->rate.numerator = encodingPtr->rate.numerator;
|
||||
|
@ -441,8 +439,7 @@ KdXVInitAdaptors(
|
|||
pat->flags = attributePtr->flags;
|
||||
pat->min_value = attributePtr->min_value;
|
||||
pat->max_value = attributePtr->max_value;
|
||||
if((pat->name = malloc(strlen(attributePtr->name) + 1)))
|
||||
strcpy(pat->name, attributePtr->name);
|
||||
pat->name = strdup(attributePtr->name);
|
||||
}
|
||||
pa->nAttributes = adaptorPtr->nAttributes;
|
||||
pa->pAttributes = pAttribute;
|
||||
|
|
|
@ -1062,10 +1062,9 @@ ddxProcessArgument(int argc, char **argv, int i)
|
|||
{
|
||||
char *mp;
|
||||
CHECK_FOR_REQUIRED_ARGUMENT();
|
||||
mp = malloc(strlen(argv[i + 1]) + 1);
|
||||
mp = strdup(argv[i + 1]);
|
||||
if (!mp)
|
||||
FatalError("Can't allocate memory for ModulePath\n");
|
||||
strcpy(mp, argv[i + 1]);
|
||||
xf86ModulePath = mp;
|
||||
xf86ModPathFrom = X_CMDLINE;
|
||||
return 2;
|
||||
|
@ -1074,10 +1073,9 @@ ddxProcessArgument(int argc, char **argv, int i)
|
|||
{
|
||||
char *lf;
|
||||
CHECK_FOR_REQUIRED_ARGUMENT();
|
||||
lf = malloc(strlen(argv[i + 1]) + 1);
|
||||
lf = strdup(argv[i + 1]);
|
||||
if (!lf)
|
||||
FatalError("Can't allocate memory for LogFile\n");
|
||||
strcpy(lf, argv[i + 1]);
|
||||
xf86LogFile = lf;
|
||||
xf86LogFileFrom = X_CMDLINE;
|
||||
return 2;
|
||||
|
|
|
@ -429,8 +429,7 @@ xf86XVInitAdaptors(
|
|||
pa->ddGetPortAttribute = xf86XVGetPortAttribute;
|
||||
pa->ddQueryBestSize = xf86XVQueryBestSize;
|
||||
pa->ddQueryImageAttributes = xf86XVQueryImageAttributes;
|
||||
if((pa->name = malloc(strlen(adaptorPtr->name) + 1)))
|
||||
strcpy(pa->name, adaptorPtr->name);
|
||||
pa->name = strdup(adaptorPtr->name);
|
||||
|
||||
if(adaptorPtr->nEncodings &&
|
||||
(pEncode = calloc(adaptorPtr->nEncodings, sizeof(XvEncodingRec)))) {
|
||||
|
@ -440,8 +439,7 @@ xf86XVInitAdaptors(
|
|||
{
|
||||
pe->id = encodingPtr->id;
|
||||
pe->pScreen = pScreen;
|
||||
if((pe->name = malloc(strlen(encodingPtr->name) + 1)))
|
||||
strcpy(pe->name, encodingPtr->name);
|
||||
pe->name = strdup(encodingPtr->name);
|
||||
pe->width = encodingPtr->width;
|
||||
pe->height = encodingPtr->height;
|
||||
pe->rate.numerator = encodingPtr->rate.numerator;
|
||||
|
@ -493,8 +491,7 @@ xf86XVInitAdaptors(
|
|||
pat->flags = attributePtr->flags;
|
||||
pat->min_value = attributePtr->min_value;
|
||||
pat->max_value = attributePtr->max_value;
|
||||
if((pat->name = malloc(strlen(attributePtr->name) + 1)))
|
||||
strcpy(pat->name, attributePtr->name);
|
||||
pat->name = strdup(attributePtr->name);
|
||||
}
|
||||
pa->nAttributes = adaptorPtr->nAttributes;
|
||||
pa->pAttributes = pAttribute;
|
||||
|
|
|
@ -212,10 +212,8 @@ LoaderOpen(const char *module, const char *cname, int handle,
|
|||
refCount[new_handle] = 1;
|
||||
|
||||
tmp = _LoaderListPush();
|
||||
tmp->name = malloc(strlen(module) + 1);
|
||||
strcpy(tmp->name, module);
|
||||
tmp->cname = malloc(strlen(cname) + 1);
|
||||
strcpy(tmp->cname, cname);
|
||||
tmp->name = strdup(module);
|
||||
tmp->cname = strdup(cname);
|
||||
tmp->handle = new_handle;
|
||||
tmp->module = moduleseq++;
|
||||
|
||||
|
|
|
@ -364,12 +364,8 @@ xf86optionListCreate( const char **options, int count, int used )
|
|||
}
|
||||
for (i = 0; i < count; i += 2)
|
||||
{
|
||||
t1 = malloc (sizeof (char) *
|
||||
(strlen (options[i]) + 1));
|
||||
strcpy (t1, options[i]);
|
||||
t2 = malloc (sizeof (char) *
|
||||
(strlen (options[i + 1]) + 1));
|
||||
strcpy (t2, options[i + 1]);
|
||||
t1 = strdup(options[i]);
|
||||
t2 = strdup(options[i + 1]);
|
||||
p = addNewOption2 (p, t1, t2, used);
|
||||
}
|
||||
|
||||
|
|
|
@ -1090,8 +1090,7 @@ void
|
|||
xf86setSection (char *section)
|
||||
{
|
||||
free(configSection);
|
||||
configSection = malloc(strlen (section) + 1);
|
||||
strcpy (configSection, section);
|
||||
configSection = strdup(section);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -479,12 +479,11 @@ static void setup_env(void) {
|
|||
pds = LAUNCHD_ID_PREFIX".X11";
|
||||
}
|
||||
|
||||
server_bootstrap_name = malloc(sizeof(char) * (strlen(pds) + 1));
|
||||
server_bootstrap_name = strdup(pds);
|
||||
if(!server_bootstrap_name) {
|
||||
fprintf(stderr, "X11.app: Memory allocation error.\n");
|
||||
exit(1);
|
||||
}
|
||||
strcpy(server_bootstrap_name, pds);
|
||||
setenv("X11_PREFS_DOMAIN", server_bootstrap_name, 1);
|
||||
|
||||
len = strlen(server_bootstrap_name);
|
||||
|
|
|
@ -444,7 +444,7 @@ glxLogExtensions(const char *prefix, const char *extensions)
|
|||
{
|
||||
int length = 0;
|
||||
char *strl;
|
||||
char *str = malloc(strlen(extensions) + 1);
|
||||
char *str = strdup(extensions);
|
||||
|
||||
if (str == NULL)
|
||||
{
|
||||
|
@ -452,9 +452,6 @@ glxLogExtensions(const char *prefix, const char *extensions)
|
|||
return;
|
||||
}
|
||||
|
||||
str[strlen(extensions)] = '\0';
|
||||
strncpy (str, extensions, strlen(extensions));
|
||||
|
||||
strl = strtok(str, " ");
|
||||
ErrorF("%s%s", prefix, strl);
|
||||
length = strlen(prefix) + strlen(strl);
|
||||
|
|
Loading…
Reference in New Issue