Get rid of xstrdup when argument is definitely non-NULL
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@dottedmag.net> Reviewed-by: Alan Coopersmith <alan.coopersmith@oracle.com>
This commit is contained in:
parent
620ca54aaa
commit
6592db6bb5
|
@ -134,6 +134,6 @@ add_option(InputOption **options, const char *key, const char *value)
|
||||||
if (!*options) /* Yeesh. */
|
if (!*options) /* Yeesh. */
|
||||||
return;
|
return;
|
||||||
(*options)->key = xstrdup(key);
|
(*options)->key = xstrdup(key);
|
||||||
(*options)->value = xstrdup(value);
|
(*options)->value = strdup(value);
|
||||||
(*options)->next = NULL;
|
(*options)->next = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,8 +86,8 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
options->key = xstrdup("_source");
|
options->key = strdup("_source");
|
||||||
options->value = xstrdup("client/dbus");
|
options->value = strdup("client/dbus");
|
||||||
if (!options->key || !options->value) {
|
if (!options->key || !options->value) {
|
||||||
ErrorF("[config/dbus] couldn't allocate first key/value pair\n");
|
ErrorF("[config/dbus] couldn't allocate first key/value pair\n");
|
||||||
ret = BadAlloc;
|
ret = BadAlloc;
|
||||||
|
@ -120,7 +120,7 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error)
|
||||||
tmp);
|
tmp);
|
||||||
MALFORMED_MESSAGE();
|
MALFORMED_MESSAGE();
|
||||||
}
|
}
|
||||||
options->key = xstrdup(tmp);
|
options->key = strdup(tmp);
|
||||||
if (!options->key) {
|
if (!options->key) {
|
||||||
ErrorF("[config/dbus] couldn't duplicate key!\n");
|
ErrorF("[config/dbus] couldn't duplicate key!\n");
|
||||||
ret = BadAlloc;
|
ret = BadAlloc;
|
||||||
|
@ -136,7 +136,7 @@ add_device(DBusMessage *message, DBusMessage *reply, DBusError *error)
|
||||||
dbus_message_iter_get_basic(&subiter, &tmp);
|
dbus_message_iter_get_basic(&subiter, &tmp);
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
MALFORMED_MESSAGE();
|
MALFORMED_MESSAGE();
|
||||||
options->value = xstrdup(tmp);
|
options->value = strdup(tmp);
|
||||||
if (!options->value) {
|
if (!options->value) {
|
||||||
ErrorF("[config/dbus] couldn't duplicate option!\n");
|
ErrorF("[config/dbus] couldn't duplicate option!\n");
|
||||||
ret = BadAlloc;
|
ret = BadAlloc;
|
||||||
|
|
14
config/hal.c
14
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);
|
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)");
|
LogMessageVerb(X_INFO, 10, "config/hal: getting %s on %s returned %s\n", name, udi, prop ? prop : "(null)");
|
||||||
if (prop) {
|
if (prop) {
|
||||||
ret = xstrdup(prop);
|
ret = strdup(prop);
|
||||||
libhal_free_string(prop);
|
libhal_free_string(prop);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -156,13 +156,13 @@ device_added(LibHalContext *hal_ctx, const char *udi)
|
||||||
LogMessage(X_WARNING,"config/hal: no driver or path specified for %s\n", udi);
|
LogMessage(X_WARNING,"config/hal: no driver or path specified for %s\n", udi);
|
||||||
goto unwind;
|
goto unwind;
|
||||||
}
|
}
|
||||||
attrs.device = xstrdup(path);
|
attrs.device = strdup(path);
|
||||||
|
|
||||||
name = get_prop_string(hal_ctx, udi, "info.product");
|
name = get_prop_string(hal_ctx, udi, "info.product");
|
||||||
if (!name)
|
if (!name)
|
||||||
name = xstrdup("(unnamed)");
|
name = strdup("(unnamed)");
|
||||||
else
|
else
|
||||||
attrs.product = xstrdup(name);
|
attrs.product = strdup(name);
|
||||||
|
|
||||||
attrs.vendor = get_prop_string(hal_ctx, udi, "info.vendor");
|
attrs.vendor = get_prop_string(hal_ctx, udi, "info.vendor");
|
||||||
hal_tags = get_prop_string(hal_ctx, udi, "input.tags");
|
hal_tags = get_prop_string(hal_ctx, udi, "input.tags");
|
||||||
|
@ -211,8 +211,8 @@ device_added(LibHalContext *hal_ctx, const char *udi)
|
||||||
goto unwind;
|
goto unwind;
|
||||||
}
|
}
|
||||||
|
|
||||||
options->key = xstrdup("_source");
|
options->key = strdup("_source");
|
||||||
options->value = xstrdup("server/hal");
|
options->value = strdup("server/hal");
|
||||||
if (!options->key || !options->value) {
|
if (!options->key || !options->value) {
|
||||||
LogMessage(X_ERROR, "config/hal: couldn't allocate first key/value pair\n");
|
LogMessage(X_ERROR, "config/hal: couldn't allocate first key/value pair\n");
|
||||||
goto unwind;
|
goto unwind;
|
||||||
|
@ -387,7 +387,7 @@ device_added(LibHalContext *hal_ctx, const char *udi)
|
||||||
|
|
||||||
for (; dev; dev = dev->next){
|
for (; dev; dev = dev->next){
|
||||||
free(dev->config_info);
|
free(dev->config_info);
|
||||||
dev->config_info = xstrdup(config_info);
|
dev->config_info = strdup(config_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
unwind:
|
unwind:
|
||||||
|
|
|
@ -86,8 +86,8 @@ device_added(struct udev_device *udev_device)
|
||||||
if (!options)
|
if (!options)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
options->key = xstrdup("_source");
|
options->key = strdup("_source");
|
||||||
options->value = xstrdup("server/udev");
|
options->value = strdup("server/udev");
|
||||||
if (!options->key || !options->value)
|
if (!options->key || !options->value)
|
||||||
goto unwind;
|
goto unwind;
|
||||||
|
|
||||||
|
@ -197,7 +197,7 @@ device_added(struct udev_device *udev_device)
|
||||||
|
|
||||||
for (; dev; dev = dev->next) {
|
for (; dev; dev = dev->next) {
|
||||||
free(dev->config_info);
|
free(dev->config_info);
|
||||||
dev->config_info = xstrdup(config_info);
|
dev->config_info = strdup(config_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
unwind:
|
unwind:
|
||||||
|
|
|
@ -1836,7 +1836,7 @@ SetDefaultFontPath(char *path)
|
||||||
if (!start) {
|
if (!start) {
|
||||||
temp_path = Xprintf("%s%sbuilt-ins", path, *path ? "," : "");
|
temp_path = Xprintf("%s%sbuilt-ins", path, *path ? "," : "");
|
||||||
} else {
|
} else {
|
||||||
temp_path = xstrdup(path);
|
temp_path = strdup(path);
|
||||||
}
|
}
|
||||||
if (!temp_path)
|
if (!temp_path)
|
||||||
return BadAlloc;
|
return BadAlloc;
|
||||||
|
|
|
@ -2433,7 +2433,7 @@ int __glXDisp_ClientInfo(__GLXclientState *cl, GLbyte *pc)
|
||||||
cl->GLClientminorVersion = req->minor;
|
cl->GLClientminorVersion = req->minor;
|
||||||
free(cl->GLClientextensions);
|
free(cl->GLClientextensions);
|
||||||
buf = (const char *)(req+1);
|
buf = (const char *)(req+1);
|
||||||
cl->GLClientextensions = xstrdup(buf);
|
cl->GLClientextensions = strdup(buf);
|
||||||
|
|
||||||
return Success;
|
return Success;
|
||||||
}
|
}
|
||||||
|
|
|
@ -356,9 +356,9 @@ void __glXScreenInit(__GLXscreen *pGlxScreen, ScreenPtr pScreen)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
pGlxScreen->pScreen = pScreen;
|
pGlxScreen->pScreen = pScreen;
|
||||||
pGlxScreen->GLextensions = xstrdup(GLServerExtensions);
|
pGlxScreen->GLextensions = strdup(GLServerExtensions);
|
||||||
pGlxScreen->GLXvendor = xstrdup(GLXServerVendorName);
|
pGlxScreen->GLXvendor = strdup(GLXServerVendorName);
|
||||||
pGlxScreen->GLXextensions = xstrdup(GLXServerExtensions);
|
pGlxScreen->GLXextensions = strdup(GLXServerExtensions);
|
||||||
|
|
||||||
/* All GLX providers must support all of the functionality required for at
|
/* 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
|
* least GLX 1.2. If the provider supports a higher version, the GLXminor
|
||||||
|
|
|
@ -1761,15 +1761,15 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
|
||||||
if (sdoodad->any.type == XkbTextDoodad) {
|
if (sdoodad->any.type == XkbTextDoodad) {
|
||||||
if (sdoodad->text.text)
|
if (sdoodad->text.text)
|
||||||
ddoodad->text.text =
|
ddoodad->text.text =
|
||||||
xstrdup(sdoodad->text.text);
|
strdup(sdoodad->text.text);
|
||||||
if (sdoodad->text.font)
|
if (sdoodad->text.font)
|
||||||
ddoodad->text.font =
|
ddoodad->text.font =
|
||||||
xstrdup(sdoodad->text.font);
|
strdup(sdoodad->text.font);
|
||||||
}
|
}
|
||||||
else if (sdoodad->any.type == XkbLogoDoodad) {
|
else if (sdoodad->any.type == XkbLogoDoodad) {
|
||||||
if (sdoodad->logo.logo_name)
|
if (sdoodad->logo.logo_name)
|
||||||
ddoodad->logo.logo_name =
|
ddoodad->logo.logo_name =
|
||||||
xstrdup(sdoodad->logo.logo_name);
|
strdup(sdoodad->logo.logo_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dsection->overlays = NULL;
|
dsection->overlays = NULL;
|
||||||
|
@ -1832,14 +1832,14 @@ _XkbCopyGeom(XkbDescPtr src, XkbDescPtr dst)
|
||||||
memcpy(ddoodad , sdoodad, sizeof(XkbDoodadRec));
|
memcpy(ddoodad , sdoodad, sizeof(XkbDoodadRec));
|
||||||
if (sdoodad->any.type == XkbTextDoodad) {
|
if (sdoodad->any.type == XkbTextDoodad) {
|
||||||
if (sdoodad->text.text)
|
if (sdoodad->text.text)
|
||||||
ddoodad->text.text = xstrdup(sdoodad->text.text);
|
ddoodad->text.text = strdup(sdoodad->text.text);
|
||||||
if (sdoodad->text.font)
|
if (sdoodad->text.font)
|
||||||
ddoodad->text.font = xstrdup(sdoodad->text.font);
|
ddoodad->text.font = strdup(sdoodad->text.font);
|
||||||
}
|
}
|
||||||
else if (sdoodad->any.type == XkbLogoDoodad) {
|
else if (sdoodad->any.type == XkbLogoDoodad) {
|
||||||
if (sdoodad->logo.logo_name)
|
if (sdoodad->logo.logo_name)
|
||||||
ddoodad->logo.logo_name =
|
ddoodad->logo.logo_name =
|
||||||
xstrdup(sdoodad->logo.logo_name);
|
strdup(sdoodad->logo.logo_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue