[PATCH:libfontenc 1/2] Replace malloc(strlen()) + strcpy() with strdup()
Alan Coopersmith
alan.coopersmith at oracle.com
Fri May 14 20:18:25 PDT 2010
Now that we use malloc directly instead of xalloc, we can use
strdup directly too.
Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
src/encparse.c | 12 ++++--------
src/fontenc.c | 3 +--
2 files changed, 5 insertions(+), 10 deletions(-)
diff --git a/src/encparse.c b/src/encparse.c
index b288c8c..33e0a05 100644
--- a/src/encparse.c
+++ b/src/encparse.c
@@ -488,10 +488,9 @@ parseEncodingFile(FontFilePtr f, int headerOnly)
encoding = malloc(sizeof(FontEncRec));
if(encoding == NULL)
goto error;
- encoding->name = malloc(strlen(keyword_value)+1);
+ encoding->name = strdup(keyword_value);
if(encoding->name == NULL)
goto error;
- strcpy(encoding->name, keyword_value);
encoding->size = 256;
encoding->row_size = 0;
encoding->mappings = NULL;
@@ -508,10 +507,9 @@ parseEncodingFile(FontFilePtr f, int headerOnly)
case EOF_LINE: goto done;
case ALIAS_LINE:
if(numaliases < MAXALIASES) {
- aliases[numaliases] = malloc(strlen(keyword_value)+1);
+ aliases[numaliases] = strdup(keyword_value);
if(aliases[numaliases] == NULL)
goto error;
- strcpy(aliases[numaliases], keyword_value);
numaliases++;
}
goto no_mapping;
@@ -718,11 +716,10 @@ parseEncodingFile(FontFilePtr f, int headerOnly)
nam[i]=NULL;
last = value1;
}
- nam[value1] = malloc(strlen(keyword_value)+1);
+ nam[value1] = strdup(keyword_value);
if(nam[value1] == NULL) {
goto error;
}
- strcpy(nam[value1], keyword_value);
goto string_mapping;
default: goto string_mapping; /* ignore unknown lines */
@@ -781,10 +778,9 @@ FontEncDirectory(void)
if(dir == NULL) {
char *c = getenv("FONT_ENCODINGS_DIRECTORY");
if(c) {
- dir = malloc(strlen(c) + 1);
+ dir = strdup(c);
if(!dir)
return NULL;
- strcpy(dir, c);
} else {
dir = FONT_ENCODINGS_DIRECTORY;
}
diff --git a/src/fontenc.c b/src/fontenc.c
index 1a24fc2..8718eff 100644
--- a/src/fontenc.c
+++ b/src/fontenc.c
@@ -753,10 +753,9 @@ FontEncLoad(const char *encoding_name, const char *filename)
char *new_name;
int numaliases = 0;
- new_name = malloc(strlen(encoding_name) + 1);
+ new_name = strdup(encoding_name);
if(new_name == NULL)
return NULL;
- strcpy(new_name, encoding_name);
if(encoding->aliases) {
for(alias = encoding->aliases; *alias; alias++)
numaliases++;
--
1.5.6.5
More information about the xorg-devel
mailing list