Implement and use an xstrdup() function

Many places in dtc use strdup(), but none of them actually check the
return value to see if the implied allocation succeeded.  This is a
potential bug, which we fix in the patch below by replacing strdup()
with an xstrdup() which in analogy to xmalloc() will quit with a fatal
error if the allocation fails.

I felt the introduciton of util.[ch] was a better choice
for utility oriented code than directly using srcpos.c
for the new string function.

This patch is a re-factoring of Dave Gibson's similar patch.

Signed-off-by: Jon Loeliger <jdl@freescale.com>
This commit is contained in:
Jon Loeliger 2008-10-03 11:12:33 -05:00
parent 68f98d7b8a
commit 879e4d2590
10 changed files with 82 additions and 18 deletions

View file

@ -39,7 +39,7 @@ static int dtc_open_one(struct dtc_file *file,
strcat(fullname, "/");
strcat(fullname, fname);
} else {
fullname = strdup(fname);
fullname = xstrdup(fname);
}
file->file = fopen(fullname, "r");
@ -85,7 +85,7 @@ struct dtc_file *dtc_open_file(const char *fname,
if (!file->file)
goto fail;
file->name = strdup(fname);
file->name = xstrdup(fname);
return file;
}