[PATCH 1/8] Get rid of xstrdup when argument is definitely non-NULL

Mikhail Gusarov dottedmag at dottedmag.net
Fri Jun 4 03:24:58 PDT 2010


Replace xstrdup with strdup when either constant string is
being duplicated or argument is guarded by conditionals and
obviously can't be NULL

Signed-off-by: Mikhail Gusarov <dottedmag at dottedmag.net>
---
 config/config.c  |    2 +-
 config/dbus.c    |    8 ++++----
 config/hal.c     |   14 +++++++-------
 config/udev.c    |    6 +++---
 dix/dixfonts.c   |    2 +-
 glx/glxcmds.c    |    2 +-
 glx/glxscreens.c |    6 +++---
 xkb/xkbUtils.c   |   12 ++++++------
 8 files changed, 26 insertions(+), 26 deletions(-)

diff --git a/config/config.c b/config/config.c
index 65ef679..d42a16a 100644
--- a/config/config.c
+++ b/config/config.c
@@ -134,6 +134,6 @@ add_option(InputOption **options, const char *key, const char *value)
     if (!*options) /* Yeesh. */
         return;
     (*options)->key = xstrdup(key);
-    (*options)->value = xstrdup(value);
+    (*options)->value = strdup(value);
     (*options)->next = NULL;
 }
diff --git a/config/dbus.c b/config/dbus.c
index 72a0a05..ee90da0 100644
--- a/config/dbus.c
+++ b/config/dbus.c
@@ -87,8 +87,8 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error)
         return BadAlloc;
     }
 
-    options->key = xstrdup("_source");
-    options->value = xstrdup("client/dbus");
+    options->key = strdup("_source");
+    options->value = strdup("client/dbus");
     if (!options->key || !options->value) {
         ErrorF("[config/dbus] couldn't allocate first key/value pair\n");
         ret = BadAlloc;
@@ -121,7 +121,7 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error)
                    tmp);
             MALFORMED_MESSAGE();
         }
-        options->key = xstrdup(tmp);
+        options->key = strdup(tmp);
         if (!options->key) {
             ErrorF("[config/dbus] couldn't duplicate key!\n");
             ret = BadAlloc;
@@ -137,7 +137,7 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error)
         dbus_message_iter_get_basic(&subiter, &tmp);
         if (!tmp)
             MALFORMED_MESSAGE();
-        options->value = xstrdup(tmp);
+        options->value = strdup(tmp);
         if (!options->value) {
             ErrorF("[config/dbus] couldn't duplicate option!\n");
             ret = BadAlloc;
diff --git a/config/hal.c b/config/hal.c
index 6a22323..15eb177 100644
--- a/config/hal.c
+++ b/config/hal.c
@@ -81,7 +81,7 @@ get_prop_string(LibHalContext *hal_ctx, const char *udi, const char *name)
     prop = libhal_device_get_property_string(hal_ctx, udi, name, NULL);
     LogMessageVerb(X_INFO, 10, "config/hal: getting %s on %s returned %s\n", name, udi, prop ? prop : "(null)");
     if (prop) {
-        ret = xstrdup(prop);
+        ret = strdup(prop);
         libhal_free_string(prop);
     }
     else {
@@ -155,13 +155,13 @@ device_added(LibHalContext *hal_ctx, const char *udi)
         LogMessage(X_WARNING,"config/hal: no driver or path specified for %s\n", udi);
         goto unwind;
     }
-    attrs.device = xstrdup(path);
+    attrs.device = strdup(path);
 
     name = get_prop_string(hal_ctx, udi, "info.product");
     if (!name)
-        name = xstrdup("(unnamed)");
+        name = strdup("(unnamed)");
     else
-        attrs.product = xstrdup(name);
+        attrs.product = strdup(name);
 
     attrs.vendor = get_prop_string(hal_ctx, udi, "info.vendor");
     attrs.tags = xstrtokenize(get_prop_string(hal_ctx, udi, "input.tags"), ",");
@@ -185,8 +185,8 @@ device_added(LibHalContext *hal_ctx, const char *udi)
         goto unwind;
     }
 
-    options->key = xstrdup("_source");
-    options->value = xstrdup("server/hal");
+    options->key = strdup("_source");
+    options->value = strdup("server/hal");
     if (!options->key || !options->value) {
         LogMessage(X_ERROR, "config/hal: couldn't allocate first key/value pair\n");
         goto unwind;
@@ -368,7 +368,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
     for (; dev; dev = dev->next){
         if (dev->config_info)
             free(dev->config_info);
-        dev->config_info = xstrdup(config_info);
+        dev->config_info = strdup(config_info);
     }
 
 unwind:
diff --git a/config/udev.c b/config/udev.c
index 5e8d8da..f1398a9 100644
--- a/config/udev.c
+++ b/config/udev.c
@@ -67,8 +67,8 @@ device_added(struct udev_device *udev_device)
     if (!options)
         return;
 
-    options->key = xstrdup("_source");
-    options->value = xstrdup("server/udev");
+    options->key = strdup("_source");
+    options->value = strdup("server/udev");
     if (!options->key || !options->value)
         goto unwind;
 
@@ -142,7 +142,7 @@ device_added(struct udev_device *udev_device)
 
     for (; dev; dev = dev->next) {
         free(dev->config_info);
-        dev->config_info = xstrdup(config_info);
+        dev->config_info = strdup(config_info);
     }
 
  unwind:
diff --git a/dix/dixfonts.c b/dix/dixfonts.c
index 51c7ab6..7635635 100644
--- a/dix/dixfonts.c
+++ b/dix/dixfonts.c
@@ -1838,7 +1838,7 @@ SetDefaultFontPath(char *path)
     if (!start) {
 	temp_path = Xprintf("%s%sbuilt-ins", path, *path ? "," : "");
     } else {
-	temp_path = xstrdup(path);
+	temp_path = strdup(path);
     }
     if (!temp_path)
         return BadAlloc;
diff --git a/glx/glxcmds.c b/glx/glxcmds.c
index 25346f9..49201d4 100644
--- a/glx/glxcmds.c
+++ b/glx/glxcmds.c
@@ -2434,7 +2434,7 @@ int __glXDisp_ClientInfo(__GLXclientState *cl, GLbyte *pc)
     if (cl->GLClientextensions)
 	free(cl->GLClientextensions);
     buf = (const char *)(req+1);
-    cl->GLClientextensions = xstrdup(buf);
+    cl->GLClientextensions = strdup(buf);
 
     return Success;
 }
diff --git a/glx/glxscreens.c b/glx/glxscreens.c
index ffe70c3..3ac98aa 100644
--- a/glx/glxscreens.c
+++ b/glx/glxscreens.c
@@ -353,9 +353,9 @@ void __glXScreenInit(__GLXscreen *pGlxScreen, ScreenPtr pScreen)
     int i;
 
     pGlxScreen->pScreen       = pScreen;
-    pGlxScreen->GLextensions  = xstrdup(GLServerExtensions);
-    pGlxScreen->GLXvendor     = xstrdup(GLXServerVendorName);
-    pGlxScreen->GLXextensions = xstrdup(GLXServerExtensions);
+    pGlxScreen->GLextensions  = strdup(GLServerExtensions);
+    pGlxScreen->GLXvendor     = strdup(GLXServerVendorName);
+    pGlxScreen->GLXextensions = strdup(GLXServerExtensions);
 
     /* All GLX providers must support all of the functionality required for at
      * least GLX 1.2.  If the provider supports a higher version, the GLXminor
diff --git a/xkb/xkbUtils.c b/xkb/xkbUtils.c
index a360a84..289ffed 100644
--- a/xkb/xkbUtils.c
+++ b/xkb/xkbUtils.c
@@ -1761,15 +1761,15 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
                     if (sdoodad->any.type == XkbTextDoodad) {
                         if (sdoodad->text.text)
                             ddoodad->text.text =
-                             xstrdup(sdoodad->text.text);
+                             strdup(sdoodad->text.text);
                         if (sdoodad->text.font)
                             ddoodad->text.font =
-                             xstrdup(sdoodad->text.font);
+                             strdup(sdoodad->text.font);
                     }
                     else if (sdoodad->any.type == XkbLogoDoodad) {
                         if (sdoodad->logo.logo_name)
                             ddoodad->logo.logo_name =
-                             xstrdup(sdoodad->logo.logo_name);
+                             strdup(sdoodad->logo.logo_name);
                     }
                 }
                 dsection->overlays = NULL;
@@ -1832,14 +1832,14 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
                 memcpy(ddoodad , sdoodad, sizeof(XkbDoodadRec));
                 if (sdoodad->any.type == XkbTextDoodad) {
                     if (sdoodad->text.text)
-                        ddoodad->text.text = xstrdup(sdoodad->text.text);
+                        ddoodad->text.text = strdup(sdoodad->text.text);
                     if (sdoodad->text.font)
-                        ddoodad->text.font = xstrdup(sdoodad->text.font);
+                        ddoodad->text.font = strdup(sdoodad->text.font);
                 }
                 else if (sdoodad->any.type == XkbLogoDoodad) {
                     if (sdoodad->logo.logo_name)
                         ddoodad->logo.logo_name =
-                          xstrdup(sdoodad->logo.logo_name);
+                          strdup(sdoodad->logo.logo_name);
                 }
             }
 
-- 
1.7.1



More information about the xorg-devel mailing list