[PATCH:libXt 3/4] Convert ResConfig.c to use XtAsprintf() instead of XtMalloc + sprintf

Alan Coopersmith alan.coopersmith at oracle.com
Mon Dec 13 16:40:27 PST 2010


Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 src/ResConfig.c |   40 +++++++++-------------------------------
 1 files changed, 9 insertions(+), 31 deletions(-)

diff --git a/src/ResConfig.c b/src/ResConfig.c
index 63afb18..68da536 100644
--- a/src/ResConfig.c
+++ b/src/ResConfig.c
@@ -174,18 +174,13 @@ _set_resource_values (
 		 * create resource name string
 		 */
 		if (resource_name) {
-			temp = XtMalloc (sizeof(char) *
-				(2 + strlen(cur->core.name)
-			   	+ strlen(resource_name)));
-			sprintf (temp, ".%s%s", cur->core.name, resource_name);
+			XtAsprintf (&temp, ".%s%s", cur->core.name, resource_name);
 			XtFree (resource_name);
 		} else if (!XtIsWidget (cur) || !cur->core.name) {
 			cur = XtParent(cur);
 			continue;
 		} else {
-			temp = XtMalloc (sizeof(char) *
-				(2 + strlen(cur->core.name)));
-			sprintf (temp, ".%s", cur->core.name);
+			XtAsprintf (&temp, ".%s", cur->core.name);
 		}
 		resource_name = temp;
 
@@ -197,31 +192,19 @@ _set_resource_values (
 				(ApplicationShellWidget) (cur);
 
 			if (resource_class) {
-				temp = XtMalloc (sizeof(char) *
-					(2 + strlen(top->application.class)
-					+ strlen(resource_class)));
-				sprintf (temp, ".%s%s",
+				XtAsprintf (&temp, ".%s%s",
 					top->application.class, resource_class);
 			} else {
-				temp = XtMalloc (sizeof(char) *
-					(2 + strlen(top->application.class)));
-				sprintf (temp, ".%s",
+				XtAsprintf (&temp, ".%s",
 					top->application.class);
 			}
 		} else {
 			if (resource_class) {
-				temp = XtMalloc (sizeof(char) *
-					(2 + strlen(
-					cur->core.widget_class->core_class.class_name)
-					+ strlen(resource_class)));
-				sprintf (temp, ".%s%s",
+				XtAsprintf (&temp, ".%s%s",
 					cur->core.widget_class->core_class.class_name,
 					resource_class);
 			} else {
-				temp = XtMalloc (sizeof(char) *
-					(2 + strlen(
-					cur->core.widget_class->core_class.class_name)));
-				sprintf (temp, ".%s",
+				XtAsprintf (&temp, ".%s",
 					cur->core.widget_class->core_class.class_name);
 			}
 		}
@@ -235,9 +218,7 @@ _set_resource_values (
 	/*
 	 * add the resource name to the end of the resource name string
 	 */
-	temp = XtMalloc (2 + strlen(resource_name) +
-		strlen(resources_return[res_index].resource_name));
-	sprintf (temp, "%s.%s", resource_name,
+	XtAsprintf (&temp, "%s.%s", resource_name,
 		resources_return[res_index].resource_name);
 	if (resource_name != NULL)
 		XtFree (resource_name);
@@ -246,9 +227,7 @@ _set_resource_values (
 	/*
 	 * add the resource class to the end of the resource class string
 	 */
-	temp = XtMalloc (2 + strlen(resource_class) +
-		strlen(resources_return[res_index].resource_class));
-	sprintf (temp, "%s.%s", resource_class,
+	XtAsprintf (&temp, "%s.%s", resource_class,
 		resources_return[res_index].resource_class);
 	if (resource_class != NULL)
 		XtFree (resource_class);
@@ -757,8 +736,7 @@ _search_widget_tree (
 	 */
 	} else {
 		if (remainder[0] != '*' && remainder[0] != '.') {
-			copy = XtMalloc (strlen(remainder) + 2);
-			sprintf (copy, ".%s", remainder);
+			XtAsprintf (&copy, ".%s", remainder);
 			XtFree (remainder);
 			remainder = copy;
 		}
-- 
1.7.3.2



More information about the xorg-devel mailing list