[PATCH:libX11 2/2] Convert malloc(strlen()); strcpy() sets to strdup

Alan Coopersmith alan.coopersmith at oracle.com
Thu Apr 14 21:38:25 PDT 2011


Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 modules/im/ximcp/imInt.c       |    6 +---
 modules/im/ximcp/imRm.c        |   19 ++++----------
 modules/im/ximcp/imTrans.c     |    3 +-
 modules/om/generic/omGeneric.c |   50 ++++++++++++---------------------------
 src/FSWrap.c                   |    3 +-
 src/InitExt.c                  |    3 +-
 src/SetLocale.c                |    3 +-
 src/xcms/PrOfId.c              |   11 +-------
 src/xkb/XKBGAlloc.c            |   13 +++-------
 src/xlibi18n/XDefaultIMIF.c    |    6 +---
 src/xlibi18n/XDefaultOMIF.c    |   25 ++++++-------------
 src/xlibi18n/lcDB.c            |   12 +++------
 src/xlibi18n/lcFile.c          |   14 +++--------
 src/xlibi18n/lcGeneric.c       |   18 ++++---------
 src/xlibi18n/lcPublic.c        |    3 +-
 15 files changed, 59 insertions(+), 130 deletions(-)

diff --git a/modules/im/ximcp/imInt.c b/modules/im/ximcp/imInt.c
index 449a42d..26f4991 100644
--- a/modules/im/ximcp/imInt.c
+++ b/modules/im/ximcp/imInt.c
@@ -214,14 +214,12 @@ _XimOpenIM(
     im->core.res_name  = NULL;
     im->core.res_class = NULL;
     if((res_name != NULL) && (*res_name != '\0')){
-	if(!(im->core.res_name  = (char *)Xmalloc(strlen(res_name)+1)))
+	if(!(im->core.res_name  = strdup(res_name)))
 	    goto Error1;
-	strcpy(im->core.res_name,res_name);
     }
     if((res_class != NULL) && (*res_class != '\0')){
-	if(!(im->core.res_class = (char *)Xmalloc(strlen(res_class)+1)))
+	if(!(im->core.res_class = strdup(res_class)))
 	    goto Error2;
-	strcpy(im->core.res_class,res_class);
     }
     if(!(im->core.im_name = _XimMakeImName(lcd)))
 	goto Error3;
diff --git a/modules/im/ximcp/imRm.c b/modules/im/ximcp/imRm.c
index 3449f91..da1207c 100644
--- a/modules/im/ximcp/imRm.c
+++ b/modules/im/ximcp/imRm.c
@@ -793,19 +793,15 @@ _XimEncodeString(
     XPointer	 	  top,
     XPointer	 	  val)
 {
-    int			  len;
     char		 *string;
     char		**out;
 
     if(val == (XPointer)NULL) {
 	return False;
     }
-    len = strlen((char *)val);
-    if(!(string = (char *)Xmalloc(len + 1))) {
+    if (!(string = strdup((char *)val))) {
 	return False;
     }
-    (void)strcpy(string, (char *)val);
-    string[len] = '\0';
 
     out = (char **)((char *)top + info->offset);
     if(*out) {
@@ -1163,21 +1159,18 @@ _XimDecodeString(
     XPointer	 	 top,
     XPointer	 	 val)
 {
-    int			 len = 0;
     char		*in;
     char		*string;
 
     in = *((char **)((char *)top + info->offset));
-    if(in != (char *)NULL) {
-	len = strlen(in);
+    if (in != NULL) {
+	string = strdup(in);
+    } else {
+	string = Xcalloc(1, 1); /* strdup("") */
     }
-    if(!(string = (char *)Xmalloc(len + 1))) {
+    if (string == NULL) {
 	return False;
     }
-    if(in != (char *)NULL) {
-	(void)strcpy(string, in);
-    }
-    string[len] = '\0';
     *((char **)val) = string;
     return True;
 }
diff --git a/modules/im/ximcp/imTrans.c b/modules/im/ximcp/imTrans.c
index e321d59..0ac08aa 100644
--- a/modules/im/ximcp/imTrans.c
+++ b/modules/im/ximcp/imTrans.c
@@ -290,7 +290,7 @@ _XimTransConf(
     char		*paddr;
     TransSpecRec	*spec;
 
-    if (!(paddr = (char *)Xmalloc(strlen(address) + 1)))
+    if (!(paddr = strdup(address)))
 	return False;
 
     if (!(spec = Xcalloc(1, sizeof(TransSpecRec)))) {
@@ -298,7 +298,6 @@ _XimTransConf(
 	return False;
     }
 
-    (void)strcpy(paddr, address);
     spec->address   = paddr;
 
     im->private.proto.spec     = (XPointer)spec;
diff --git a/modules/om/generic/omGeneric.c b/modules/om/generic/omGeneric.c
index e358796..7f02c85 100644
--- a/modules/om/generic/omGeneric.c
+++ b/modules/om/generic/omGeneric.c
@@ -523,9 +523,7 @@ get_font_name(
     if (list == NULL)
 	return NULL;
 
-    name = (char *) Xmalloc(strlen(*list) + 1);
-    if (name)
-	strcpy(name, *list);
+    name = strdup(*list);
 
     XFreeFontNames(list);
 
@@ -549,10 +547,9 @@ get_rotate_fontname(
        || len > XLFD_MAX_LEN)
 	return NULL;
 
-    pattern = (char *)Xmalloc(len + 1);
+    pattern = strdup(font_name);
     if(!pattern)
 	return NULL;
-    strcpy(pattern, font_name);
 
     memset(fields, 0, sizeof(char *) * 14);
     ptr = pattern;
@@ -661,10 +658,8 @@ get_font_name_from_list(
     for (i = 0; i < count; i++) {
         fname = list[i];
         if(is_match_charset(font_data, fname) == True) {
-             name = (char *) Xmalloc(strlen(fname) + 1);
-             if (name)
-	         strcpy(name, fname);
-             break;
+            name = strdup(fname);
+            break;
         }
     }
 
@@ -685,11 +680,10 @@ parse_all_name(
     if(is_match_charset(font_data, pattern) != True)
  	return False;
 
-    font_data->xlfd_name = (char *)Xmalloc(strlen(pattern)+1);
+    font_data->xlfd_name = strdup(pattern);
     if(font_data->xlfd_name == NULL)
 	return (-1);
 
-    strcpy(font_data->xlfd_name, pattern);
     return True;
 #else  /* OLDCODE */
     Display *dpy = oc->core.om->core.display;
@@ -723,11 +717,10 @@ parse_all_name(
         }
     }
 
-    font_data->xlfd_name = (char *)Xmalloc(strlen(pattern)+1);
+    font_data->xlfd_name = strdup(pattern);
     if(font_data->xlfd_name == NULL)
 	return (-1);
 
-    strcpy(font_data->xlfd_name, pattern);
     return True;
 #endif /* OLDCODE */
 }
@@ -946,12 +939,9 @@ parse_fontdata(
 		* -- jjw/pma (HP)
 		*/
 		if (font_data_return) {
-		    font_data_return->xlfd_name = (char *)Xmalloc
-			(strlen(font_data->xlfd_name) + 1);
+		    font_data_return->xlfd_name = strdup(font_data->xlfd_name);
 		    if (!font_data_return->xlfd_name) return -1;
 
-		    strcpy (font_data_return->xlfd_name, font_data->xlfd_name);
-
 		    font_data_return->side      = font_data->side;
 		}
 #ifdef FONTDEBUG
@@ -996,11 +986,9 @@ parse_fontdata(
 #ifdef FONTDEBUG
 		fprintf(stderr,"XLFD name: %s\n",font_data->xlfd_name);
 #endif
-		font_data_return->xlfd_name = (char *)Xmalloc
-			(strlen(font_data->xlfd_name) + 1);
+		font_data_return->xlfd_name = strdup(font_data->xlfd_name);
                 if (!font_data_return->xlfd_name) return -1;
 
-	        strcpy (font_data_return->xlfd_name, font_data->xlfd_name);
 	        font_data_return->side      = font_data->side;
 	    }
 
@@ -1192,11 +1180,10 @@ parse_fontname(
 		 * be matched. It returns the required information in
 		 * font_data_return.
 		 */
-		font_set->font_name = (char *)Xmalloc
-			(strlen(font_data_return.xlfd_name) + 1);
+		font_set->font_name = strdup(font_data_return.xlfd_name);
 		if(font_set->font_name == (char *) NULL)
 		    goto err;
-		strcpy(font_set->font_name, font_data_return.xlfd_name);
+
 		font_set->side = font_data_return.side;
 
                 Xfree (font_data_return.xlfd_name);
@@ -1223,11 +1210,10 @@ parse_fontname(
 			break;
 		    }
 		}
-		font_set->font_name = (char *)Xmalloc
-		    	(strlen(font_set->substitute[i].xlfd_name) + 1);
+		font_set->font_name = strdup(font_set->substitute[i].xlfd_name);
 		if(font_set->font_name == (char *) NULL)
 		    goto err;
-		strcpy(font_set->font_name,font_set->substitute[i].xlfd_name);
+
 		font_set->side = font_set->substitute[i].side;
 		if(parse_vw(oc, font_set, name_list, count) == -1)
 		    goto err;
@@ -1237,11 +1223,10 @@ parse_fontname(
 	}
     }
 
-    base_name = (char *) Xmalloc(strlen(oc->core.base_name_list) + 1);
+    base_name = strdup(oc->core.base_name_list);
     if (base_name == NULL)
 	goto err;
 
-    strcpy(base_name, oc->core.base_name_list);
     oc->core.base_name_list = base_name;
 
     XFreeStringList(name_list);
@@ -1850,16 +1835,14 @@ create_om(
     om->core.display = dpy;
     om->core.rdb = rdb;
     if (res_name) {
-	om->core.res_name = (char *) Xmalloc(strlen(res_name) + 1);
+	om->core.res_name = strdup(res_name);
 	if (om->core.res_name == NULL)
 	    goto err;
-	strcpy(om->core.res_name, res_name);
     }
     if (res_class) {
-	om->core.res_class = (char *) Xmalloc(strlen(res_class) + 1);
+	om->core.res_class = strdup(res_class);
 	if (om->core.res_class == NULL)
 	    goto err;
-	strcpy(om->core.res_class, res_class);
     }
 
     if (om_resources[0].xrm_name == NULLQUARK)
@@ -2014,10 +1997,9 @@ init_om(
 
     _XlcGetResource(lcd, "XLC_FONTSET", "object_name", &value, &count);
     if (count > 0) {
-	gen->object_name = (char *) Xmalloc(strlen(*value) + 1);
+	gen->object_name = strdup(*value);
 	if (gen->object_name == NULL)
 	    return False;
-	strcpy(gen->object_name, *value);
     }
 
     for (num = 0; ; num++) {
diff --git a/src/FSWrap.c b/src/FSWrap.c
index 94d94fb..45a2c34 100644
--- a/src/FSWrap.c
+++ b/src/FSWrap.c
@@ -85,10 +85,9 @@ _XParseBaseFontNameList(
     if (!*str)
 	return (char **)NULL;
 
-    if (!(ptr = Xmalloc((unsigned)strlen(str) + 1))) {
+    if (!(ptr = strdup(str))) {
 	return (char **)NULL;
     }
-    strcpy(ptr, str);
 
     psave = ptr;
     /* somebody who specifies more than XMAXLIST basefontnames will lose */
diff --git a/src/InitExt.c b/src/InitExt.c
index cb9191d..19515cc 100644
--- a/src/InitExt.c
+++ b/src/InitExt.c
@@ -50,14 +50,13 @@ XExtCodes *XInitExtension (
 
 	LockDisplay (dpy);
 	if (! (ext = (_XExtension *) Xcalloc (1, sizeof (_XExtension))) ||
-	    ! (ext->name = Xmalloc((unsigned) strlen(name) + 1))) {
+	    ! (ext->name = strdup(name))) {
 	    if (ext) Xfree((char *) ext);
 	    UnlockDisplay(dpy);
 	    return (XExtCodes *) NULL;
 	}
 	codes.extension = dpy->ext_number++;
 	ext->codes = codes;
-	(void) strcpy(ext->name, name);
 
 	/* chain it onto the display list */
 	ext->next = dpy->ext_procs;
diff --git a/src/SetLocale.c b/src/SetLocale.c
index 00c76ee..c49cb2e 100644
--- a/src/SetLocale.c
+++ b/src/SetLocale.c
@@ -103,13 +103,12 @@ _Xsetlocale(
     if (!methods)
 	return NULL;
     name = (*methods->lcname)(state);
-    xsl_name = Xmalloc(strlen(name) + 1);
+    xsl_name = strdup(name);
     if (!xsl_name) {
 	xsl_name = old_name;
 	(*methods->destroy)(state);
 	return NULL;
     }
-    strcpy(xsl_name, name);
     if (old_name)
 	Xfree(old_name);
     (*methods->destroy)(state);
diff --git a/src/xcms/PrOfId.c b/src/xcms/PrOfId.c
index 831f17a..a96d28c 100644
--- a/src/xcms/PrOfId.c
+++ b/src/xcms/PrOfId.c
@@ -66,7 +66,6 @@ XcmsPrefixOfFormat(
  */
 {
     XcmsColorSpace	**papColorSpaces;
-    char *prefix;
 
     /*
      * First try Device-Independent color spaces
@@ -75,10 +74,7 @@ XcmsPrefixOfFormat(
     if (papColorSpaces != NULL) {
 	while (*papColorSpaces != NULL) {
 	    if ((*papColorSpaces)->id == id) {
-		prefix = (char *)Xmalloc((strlen((*papColorSpaces)->prefix) +
-		1) * sizeof(char));
-		strcpy(prefix, (*papColorSpaces)->prefix);
-		return(prefix);
+		return strdup((*papColorSpaces)->prefix);
 	    }
 	    papColorSpaces++;
 	}
@@ -91,10 +87,7 @@ XcmsPrefixOfFormat(
     if (papColorSpaces != NULL) {
 	while (*papColorSpaces != NULL) {
 	    if ((*papColorSpaces)->id == id) {
-		prefix = (char *)Xmalloc((strlen((*papColorSpaces)->prefix) +
-		1) * sizeof(char));
-		strcpy(prefix, (*papColorSpaces)->prefix);
-		return(prefix);
+		return strdup((*papColorSpaces)->prefix);
 	    }
 	    papColorSpaces++;
 	}
diff --git a/src/xkb/XKBGAlloc.c b/src/xkb/XKBGAlloc.c
index 90ec2f9..7679496 100644
--- a/src/xkb/XKBGAlloc.c
+++ b/src/xkb/XKBGAlloc.c
@@ -684,9 +684,7 @@ register XkbPropertyPtr prop;
 	if ((prop->name)&&(strcmp(name,prop->name)==0)) {
 	    if (prop->value)
 		_XkbFree(prop->value);
-	    prop->value= (char *)_XkbAlloc(strlen(value)+1);
-	    if (prop->value)
-		strcpy(prop->value,value);
+	    prop->value= strdup(value);
 	    return prop;
 	}
     }
@@ -695,17 +693,15 @@ register XkbPropertyPtr prop;
 	return NULL;
     }
     prop= &geom->properties[geom->num_properties];
-    prop->name= (char *)_XkbAlloc(strlen(name)+1);
+    prop->name= strdup(name);
     if (!prop->name)
 	return NULL;
-    strcpy(prop->name,name);
-    prop->value= (char *)_XkbAlloc(strlen(value)+1);
+    prop->value= strdup(value);
     if (!prop->value) {
 	_XkbFree(prop->name);
 	prop->name= NULL;
 	return NULL;
     }
-    strcpy(prop->value,value);
     geom->num_properties++;
     return prop;
 }
@@ -757,10 +753,9 @@ register XkbColorPtr color;
     }
     color= &geom->colors[geom->num_colors];
     color->pixel= pixel;
-    color->spec= (char *)_XkbAlloc(strlen(spec)+1);
+    color->spec= strdup(spec);
     if (!color->spec)
 	return NULL;
-    strcpy(color->spec,spec);
     geom->num_colors++;
     return color;
 }
diff --git a/src/xlibi18n/XDefaultIMIF.c b/src/xlibi18n/XDefaultIMIF.c
index ca6ee29..e97d2f4 100644
--- a/src/xlibi18n/XDefaultIMIF.c
+++ b/src/xlibi18n/XDefaultIMIF.c
@@ -226,12 +226,10 @@ _XDefaultOpenIM(
     local_impart->ctow_conv = ctow_conv;
 
     if ((res_name != NULL) && (*res_name != '\0')){
-	im->core.res_name  = (char *)Xmalloc(strlen(res_name)+1);
-	strcpy(im->core.res_name,res_name);
+	im->core.res_name  = strdup(res_name);
     }
     if ((res_class != NULL) && (*res_class != '\0')){
-	im->core.res_class = (char *)Xmalloc(strlen(res_class)+1);
-	strcpy(im->core.res_class,res_class);
+	im->core.res_class = strdup(res_class);
     }
 
     return (XIM)im;
diff --git a/src/xlibi18n/XDefaultOMIF.c b/src/xlibi18n/XDefaultOMIF.c
index 85d63e8..b1dc66d 100644
--- a/src/xlibi18n/XDefaultOMIF.c
+++ b/src/xlibi18n/XDefaultOMIF.c
@@ -216,9 +216,8 @@ check_fontname(
 		fname = prop_fname;
 	}
 	if (data) {
-	    font_set->font_name = (char *) Xmalloc(strlen(fname) + 1);
+	    font_set->font_name = strdup(fname);
 	    if (font_set->font_name) {
-		strcpy(font_set->font_name, fname);
 		found_num++;
 	    }
 	}
@@ -387,9 +386,7 @@ get_font_name(
 
     list = XListFonts(dpy, pattern, 1, &count);
     if (list != NULL) {
-	name = (char *) Xmalloc(strlen(*list) + 1);
-	if (name)
-	    strcpy(name, *list);
+	name = strdup(*list);
 
 	XFreeFontNames(list);
     } else {
@@ -459,13 +456,11 @@ parse_fontname(
 	    if (font_data == NULL)
 		continue;
 
-	    font_set->font_name = (char *) Xmalloc(strlen(font_name) + 1);
+	    font_set->font_name = strdup(font_name);
+	    Xfree(font_name);
 	    if (font_set->font_name == NULL) {
-		Xfree(font_name);
 		goto err;
 	    }
-	    strcpy(font_set->font_name, font_name);
-	    Xfree(font_name);
 	    found_num++;
 	    goto found;
 	}
@@ -548,11 +543,10 @@ Limit the length of the string copy to prevent stack corruption.
 	}
     }
   found:
-    base_name = (char *) Xmalloc(strlen(oc->core.base_name_list) + 1);
+    base_name = strdup(oc->core.base_name_list);
     if (base_name == NULL)
 	goto err;
 
-    strcpy(base_name, oc->core.base_name_list);
     oc->core.base_name_list = base_name;
 
     XFreeStringList(name_list);
@@ -1177,10 +1171,9 @@ This one is fine.  *value points to one of the local strings in
 supported_charset_list[].
 */
 	strcpy(buf, *value++);
-	font_data->name = (char *) Xmalloc(strlen(buf) + 1);
+	font_data->name = strdup(buf);
 	if (font_data->name == NULL)
 	    return False;
-	strcpy(font_data->name, buf);
     }
 
     length += strlen(data->font_data->name) + 1;
@@ -1241,16 +1234,14 @@ _XDefaultOpenOM(XLCd lcd, Display *dpy, XrmDatabase rdb,
     om->core.display = dpy;
     om->core.rdb = rdb;
     if (res_name) {
-	om->core.res_name = (char *)Xmalloc(strlen(res_name) + 1);
+	om->core.res_name = strdup(res_name);
 	if (om->core.res_name == NULL)
 	    goto err;
-	strcpy(om->core.res_name, res_name);
     }
     if (res_class) {
-	om->core.res_class = (char *)Xmalloc(strlen(res_class) + 1);
+	om->core.res_class = strdup(res_class);
 	if (om->core.res_class == NULL)
 	    goto err;
-	strcpy(om->core.res_class, res_class);
     }
 
     if (om_resources[0].xrm_name == NULLQUARK)
diff --git a/src/xlibi18n/lcDB.c b/src/xlibi18n/lcDB.c
index c6eb7f0..97b22ac 100644
--- a/src/xlibi18n/lcDB.c
+++ b/src/xlibi18n/lcDB.c
@@ -596,20 +596,18 @@ store_to_database(
 	goto err;
     }
 
-    new->category = (char *)Xmalloc(strlen(parse_info.category) + 1);
+    new->category = strdup(parse_info.category);
     if (new->category == NULL) {
 	goto err;
     }
-    strcpy(new->category, parse_info.category);
 
     if (! construct_name(name, sizeof(name))) {
 	goto err;
     }
-    new->name = (char *)Xmalloc(strlen(name) + 1);
+    new->name = strdup(name);
     if (new->name == NULL) {
 	goto err;
     }
-    strcpy(new->name, name);
     new->next = *db;
     new->value = parse_info.value;
     new->value_num = parse_info.value_num;
@@ -943,10 +941,9 @@ f_default(
     case S_NULL:
 	if (parse_info.category != NULL)
 	    goto err;
-	p = (char *)Xmalloc(strlen(wordp) + 1);
+	p = strdup(wordp);
 	if (p == NULL)
 	    goto err;
-	strcpy(p, wordp);
 	parse_info.category = p;
 	parse_info.pre_state = S_CATEGORY;
 	break;
@@ -960,10 +957,9 @@ f_default(
 		break;
 	    }
 	}
-	p = (char *)Xmalloc(strlen(wordp) + 1);
+	p = strdup(wordp);
 	if (p == NULL)
 	    goto err;
-	strcpy(p, wordp);
 	if (parse_info.name[parse_info.nest_depth] != NULL) {
 	    Xfree(parse_info.name[parse_info.nest_depth]);
 	}
diff --git a/src/xlibi18n/lcFile.c b/src/xlibi18n/lcFile.c
index 18756c1..4e44397 100644
--- a/src/xlibi18n/lcFile.c
+++ b/src/xlibi18n/lcFile.c
@@ -423,10 +423,7 @@ resolve_name(
 	    from = args[1], to = args[0];	/* right to left */
 	}
 	if (! strcmp(from, lc_name)) {
-	    name = Xmalloc(strlen(to) + 1);
-	    if (name != NULL) {
-		strcpy(name, to);
-	    }
+	    name = strdup(to);
 	    break;
 	}
     }
@@ -579,8 +576,7 @@ _XlcResolveLocaleName(
 
     if (name == NULL) {
 	/* vendor locale name == Xlocale name, no expansion of alias */
-	pub->siname = Xmalloc (strlen (lc_name) + 1);
-	strcpy (pub->siname, lc_name);
+	pub->siname = strdup (lc_name);
     } else {
 	pub->siname = name;
     }
@@ -729,8 +725,7 @@ _XlcLocaleDirName(char *dir_name, size_t dir_len, char *lc_name)
     last_dir_len = strlen (dir_name) + 1;
     last_dir_name = Xmalloc (last_dir_len);
     strcpy (last_dir_name, dir_name);
-    last_lc_name = Xmalloc (strlen (lc_name) + 1);
-    strcpy (last_lc_name, lc_name);
+    last_lc_name = strdup (lc_name);
 
     return dir_name;
 }
@@ -828,8 +823,7 @@ _XlcLocaleLibDirName(char *dir_name, size_t dir_len, char *lc_name)
     last_dir_len = strlen (dir_name) + 1;
     last_dir_name = Xmalloc (last_dir_len);
     strcpy (last_dir_name, dir_name);
-    last_lc_name = Xmalloc (strlen (lc_name) + 1);
-    strcpy (last_lc_name, lc_name);
+    last_lc_name = strdup (lc_name);
 
     return dir_name;
 }
diff --git a/src/xlibi18n/lcGeneric.c b/src/xlibi18n/lcGeneric.c
index df392e9..619cb47 100644
--- a/src/xlibi18n/lcGeneric.c
+++ b/src/xlibi18n/lcGeneric.c
@@ -215,10 +215,9 @@ add_parse_list(
     unsigned char ch;
     int num;
 
-    str = (char *) Xmalloc(strlen(encoding) + 1);
+    str = strdup(encoding);
     if (str == NULL)
         return False;
-    strcpy(str, encoding);
 
     new = Xcalloc(1, sizeof(ParseInfoRec));
     if (new == NULL)
@@ -463,10 +462,9 @@ read_charset_define(
                 break;
         }
         if (new) {
-            tmp = (char *)Xmalloc(strlen(cset_name)+1);
+            tmp = strdup(cset_name);
             if (tmp == NULL)
                 return;
-            strcpy(tmp,cset_name);
             charsetd->name = tmp;
         }
         /* side   */
@@ -522,8 +520,7 @@ read_charset_define(
                 Xfree(charsetd->encoding_name);
             }
 */
-            tmp = (char *)Xmalloc(strlen(value[0])+1);
-            strcpy(tmp,value[0]);
+            tmp = strdup(value[0]);
             charsetd->encoding_name = tmp;
             charsetd->xrm_encoding_name = XrmStringToQuark(tmp);
         }
@@ -593,10 +590,9 @@ read_segmentconversion(
         if (num > 0) {
             char *tmp;
             _XlcDbg_printValue(name,value,num);
-            tmp = (char *)Xmalloc(strlen(value[0])+1);
+            tmp = strdup(value[0]);
             if (tmp == NULL)
                 return;
-            strcpy(tmp,value[0]);
             conversion->source_encoding = tmp;
             conversion->source = srch_charset_define(tmp,&new);
         }
@@ -606,10 +602,9 @@ read_segmentconversion(
         if (num > 0) {
             char *tmp;
             _XlcDbg_printValue(name,value,num);
-            tmp = (char *)Xmalloc(strlen(value[0])+1);
+            tmp = strdup(value[0]);
             if (tmp == NULL)
                 return;
-            strcpy(tmp,value[0]);
             conversion->destination_encoding = tmp;
             conversion->dest = srch_charset_define(tmp,&new);
         }
@@ -645,12 +640,11 @@ create_ctextseg(
     ret = (ExtdSegment)Xmalloc(sizeof(ExtdSegmentRec));
     if (ret == NULL)
         return NULL;
-    ret->name = (char *)Xmalloc(strlen(value[0]) + 1);
+    ret->name = strdup(value[0]);
     if (ret->name == NULL) {
         Xfree (ret);
         return NULL;
     }
-    strcpy(ret->name,value[0]);
     cset_name = (char*) Xmalloc (strlen(ret->name) + 1);
     if (cset_name == NULL) {
         Xfree (ret->name);
diff --git a/src/xlibi18n/lcPublic.c b/src/xlibi18n/lcPublic.c
index 43b9286..1b1fb54 100644
--- a/src/xlibi18n/lcPublic.c
+++ b/src/xlibi18n/lcPublic.c
@@ -128,10 +128,9 @@ load_public(
 
     _XlcGetResource(lcd, "XLC_XLOCALE", "encoding_name", &values, &num);
     str = (num > 0) ? values[0] : "STRING";
-    pub->encoding_name = (char*) Xmalloc(strlen(str) + 1);
+    pub->encoding_name = strdup(str);
     if (pub->encoding_name == NULL)
 	return False;
-    strcpy(pub->encoding_name, str);
 
     return True;
 }
-- 
1.7.3.2



More information about the xorg-devel mailing list