Convert some malloc + strncpy pairs into strndup calls
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com> Reviewed-by: Jeremy Huddleston <jeremyhu@apple.com>
This commit is contained in:
parent
acde97a39d
commit
08093c25a9
|
@ -118,14 +118,11 @@ MakeAtom(const char *string, unsigned len, Bool makeit)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
char *newstring = malloc(len + 1);
|
nd->string = strndup(string, len);
|
||||||
if (!newstring) {
|
if (!nd->string) {
|
||||||
free(nd);
|
free(nd);
|
||||||
return BAD_RESOURCE;
|
return BAD_RESOURCE;
|
||||||
}
|
}
|
||||||
strncpy(newstring, string, (int)len);
|
|
||||||
newstring[len] = 0;
|
|
||||||
nd->string = newstring;
|
|
||||||
}
|
}
|
||||||
if ((lastAtom + 1) >= tableLength) {
|
if ((lastAtom + 1) >= tableLength) {
|
||||||
NodePtr *table;
|
NodePtr *table;
|
||||||
|
|
|
@ -1049,12 +1049,10 @@ KdGetOptions (InputOption **options, char *string)
|
||||||
if (strchr(string, '='))
|
if (strchr(string, '='))
|
||||||
{
|
{
|
||||||
tam_key = (strchr(string, '=') - string);
|
tam_key = (strchr(string, '=') - string);
|
||||||
key = malloc(tam_key + 1);
|
key = strndup(string, tam_key);
|
||||||
if (!key)
|
if (!key)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
strncpy(key, string, tam_key);
|
|
||||||
key[tam_key] = '\0';
|
|
||||||
value = strdup(strchr(string, '=') + 1);
|
value = strdup(strchr(string, '=') + 1);
|
||||||
if (!value)
|
if (!value)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
|
@ -1664,13 +1664,11 @@ CheckUserParameters(int argc, char **argv, char **envp)
|
||||||
if (!eq)
|
if (!eq)
|
||||||
continue;
|
continue;
|
||||||
len = eq - envp[i];
|
len = eq - envp[i];
|
||||||
e = malloc(len + 1);
|
e = strndup(envp[i], len);
|
||||||
if (!e) {
|
if (!e) {
|
||||||
bad = InternalError;
|
bad = InternalError;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
strncpy(e, envp[i], len);
|
|
||||||
e[len] = 0;
|
|
||||||
if (len >= 4 &&
|
if (len >= 4 &&
|
||||||
(strcmp(e + len - 4, "PATH") == 0 ||
|
(strcmp(e + len - 4, "PATH") == 0 ||
|
||||||
strcmp(e, "TERMCAP") == 0)) {
|
strcmp(e, "TERMCAP") == 0)) {
|
||||||
|
|
Loading…
Reference in New Issue