[PATCH:xdm 4/5] Stop casting return values of malloc and friends
Alan Coopersmith
alan.coopersmith at oracle.com
Sat May 14 11:01:32 PDT 2011
It's not needed on modern mallocs that return void *, and can hide
missing prototype errors that cause the compiler to assume int is
returned (a bad thing to assume in 64-bit builds).
Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
chooser/chooser.c | 8 ++++----
xdm/access.c | 4 ++--
xdm/auth.c | 7 +++----
xdm/choose.c | 4 ++--
xdm/dpylist.c | 2 +-
xdm/file.c | 7 +++----
xdm/krb5auth.c | 7 +++----
xdm/mitauth.c | 6 +++---
xdm/policy.c | 2 +-
xdm/protodpy.c | 4 ++--
xdm/resource.c | 2 +-
xdm/rpcauth.c | 6 +++---
xdm/server.c | 2 +-
xdm/session.c | 2 +-
xdm/util.c | 8 ++++----
xdm/xdmauth.c | 8 ++++----
xdm/xdmcp.c | 4 ++--
17 files changed, 40 insertions(+), 43 deletions(-)
diff --git a/chooser/chooser.c b/chooser/chooser.c
index 6033fb4..dc1b89a 100644
--- a/chooser/chooser.c
+++ b/chooser/chooser.c
@@ -304,7 +304,7 @@ RebuildTable (int size)
if (size)
{
- newTable = (char **) malloc (size * sizeof (char *));
+ newTable = malloc (size * sizeof (char *));
if (!newTable)
return;
for (names = hostNamedb, i = 0; names; names = names->next, i++)
@@ -360,7 +360,7 @@ AddHostname (ARRAY8Ptr hostname, ARRAY8Ptr status, struct sockaddr *addr, int wi
}
if (!*names)
{
- new = (HostName *) malloc (sizeof (HostName));
+ new = malloc (sizeof (HostName));
if (!new)
return 0;
if (hostname->length)
@@ -545,10 +545,10 @@ RegisterHostaddr (struct sockaddr *addr, int len, xdmOpCode type)
{
HostAddr *host, **prev;
- host = (HostAddr *) malloc (sizeof (HostAddr));
+ host = malloc (sizeof (HostAddr));
if (!host)
return;
- host->addr = (struct sockaddr *) malloc (len);
+ host->addr = malloc (len);
if (!host->addr)
{
free (host);
diff --git a/xdm/access.c b/xdm/access.c
index 8db64b3..d0850ad 100644
--- a/xdm/access.c
+++ b/xdm/access.c
@@ -303,7 +303,7 @@ tryagain:
hostOrAlias = ReadWord (file, TRUE);
if (!hostOrAlias)
return NULL;
- h = (HostEntry *) malloc (sizeof (DisplayEntry));
+ h = malloc (sizeof (DisplayEntry));
h->hopCount = 1;
if (*hostOrAlias == ALIAS_CHARACTER)
{
@@ -422,7 +422,7 @@ tryagain:
displayOrAlias = ReadWord (file, FALSE);
if (!displayOrAlias)
return NULL;
- d = (DisplayEntry *) malloc (sizeof (DisplayEntry));
+ d = malloc (sizeof (DisplayEntry));
d->notAllowed = 0;
d->notBroadcast = 0;
d->chooser = 0;
diff --git a/xdm/auth.c b/xdm/auth.c
index 10791d2..8b6e1ec 100644
--- a/xdm/auth.c
+++ b/xdm/auth.c
@@ -506,13 +506,12 @@ SetLocalAuthorization (struct display *d)
;
d->authNameNum = i;
free (d->authNameLens);
- d->authNameLens = (unsigned short *) malloc
- (d->authNameNum * sizeof (unsigned short));
+ d->authNameLens = malloc (d->authNameNum * sizeof (unsigned short));
if (!d->authNameLens)
return;
for (i = 0; i < d->authNameNum; i++)
d->authNameLens[i] = strlen (d->authNames[i]);
- auths = (Xauth **) malloc (d->authNameNum * sizeof (Xauth *));
+ auths = malloc (d->authNameNum * sizeof (Xauth *));
if (!auths)
return;
j = 0;
@@ -675,7 +674,7 @@ saveEntry (Xauth *auth)
{
struct addrList *new;
- new = (struct addrList *) malloc (sizeof (struct addrList));
+ new = malloc (sizeof (struct addrList));
if (!new) {
LogOutOfMem ("saveEntry");
return;
diff --git a/xdm/choose.c b/xdm/choose.c
index 05a58b8..6f077eb 100644
--- a/xdm/choose.c
+++ b/xdm/choose.c
@@ -127,7 +127,7 @@ RememberIndirectClient (
if (XdmcpARRAY8Equal (clientAddress, &i->client) &&
connectionType == i->connectionType)
return 1;
- i = (IndirectUsersPtr) malloc (sizeof (IndirectUsersRec));
+ i = malloc (sizeof (IndirectUsersRec));
if (!XdmcpCopyARRAY8 (clientAddress, &i->client))
{
free (i);
@@ -311,7 +311,7 @@ RegisterIndirectChoice (
insert = 0;
if (!c)
{
- c = (ChoicePtr) malloc (sizeof (ChoiceRec));
+ c = malloc (sizeof (ChoiceRec));
insert = 1;
if (!c)
return 0;
diff --git a/xdm/dpylist.c b/xdm/dpylist.c
index ad50e76..4418894 100644
--- a/xdm/dpylist.c
+++ b/xdm/dpylist.c
@@ -181,7 +181,7 @@ NewDisplay (char *name, char *class)
{
struct display *d;
- d = (struct display *) calloc (1, sizeof (struct display));
+ d = calloc (1, sizeof (struct display));
if (!d) {
LogOutOfMem ("NewDisplay");
return NULL;
diff --git a/xdm/file.c b/xdm/file.c
index 9cb0922..6e929b8 100644
--- a/xdm/file.c
+++ b/xdm/file.c
@@ -76,14 +76,13 @@ splitIntoWords (char *s)
++s;
if (!args)
{
- args = (char **) malloc (2 * sizeof (char *));
+ args = malloc (2 * sizeof (char *));
if (!args)
return NULL;
}
else
{
- newargs = (char **) realloc ((char *) args,
- (nargs+2)*sizeof (char *));
+ newargs = realloc ((char *) args, (nargs+2)*sizeof (char *));
if (!newargs)
{
freeFileArgs (args);
@@ -113,7 +112,7 @@ copyArgs (char **args)
for (a = args; *a; a++)
/* SUPPRESS 530 */
;
- new = (char **) malloc ((a - args + 1) * sizeof (char *));
+ new = malloc ((a - args + 1) * sizeof (char *));
if (!new)
return NULL;
n = new;
diff --git a/xdm/krb5auth.c b/xdm/krb5auth.c
index 094e54a..c4498d0 100644
--- a/xdm/krb5auth.c
+++ b/xdm/krb5auth.c
@@ -95,7 +95,7 @@ Krb5GetAuthFor(unsigned short namelen, char *name, char *dname)
char *filename;
struct stat statbuf;
- new = (Xauth *) malloc (sizeof *new);
+ new = malloc (sizeof *new);
if (!new)
return (Xauth *) 0;
new->family = FamilyWild;
@@ -107,7 +107,7 @@ Krb5GetAuthFor(unsigned short namelen, char *name, char *dname)
if (dname)
{
filename = Krb5CCacheName(dname);
- new->data = (char *) malloc (3 + strlen(filename) + 1);
+ new->data = malloc (3 + strlen(filename) + 1);
if (!new->data)
{
free (filename);
@@ -125,7 +125,7 @@ Krb5GetAuthFor(unsigned short namelen, char *name, char *dname)
new->data_length = 0;
}
- new->name = (char *) malloc (namelen);
+ new->name = malloc (namelen);
if (!new->name)
{
free (new->data);
@@ -137,7 +137,6 @@ Krb5GetAuthFor(unsigned short namelen, char *name, char *dname)
return new;
}
-
Xauth *
Krb5GetAuth (unsigned short namelen, char *name)
{
diff --git a/xdm/mitauth.c b/xdm/mitauth.c
index 372d2cf..d100798 100644
--- a/xdm/mitauth.c
+++ b/xdm/mitauth.c
@@ -56,7 +56,7 @@ Xauth *
MitGetAuth (unsigned short namelen, char *name)
{
Xauth *new;
- new = (Xauth *) malloc (sizeof (Xauth));
+ new = malloc (sizeof (Xauth));
if (!new)
return (Xauth *) 0;
@@ -66,13 +66,13 @@ MitGetAuth (unsigned short namelen, char *name)
new->number_length = 0;
new->number = NULL;
- new->data = (char *) malloc (AUTH_DATA_LEN);
+ new->data = malloc (AUTH_DATA_LEN);
if (!new->data)
{
free (new);
return (Xauth *) 0;
}
- new->name = (char *) malloc (namelen);
+ new->name = malloc (namelen);
if (!new->name)
{
free (new->data);
diff --git a/xdm/policy.c b/xdm/policy.c
index 33a14f6..835fccf 100644
--- a/xdm/policy.c
+++ b/xdm/policy.c
@@ -157,7 +157,7 @@ Willing (
snprintf (statusBuf, sizeof(statusBuf), "Willing to manage");
}
status->length = strlen (statusBuf);
- status->data = (CARD8Ptr) malloc (status->length);
+ status->data = malloc (status->length);
if (!status->data)
status->length = 0;
else
diff --git a/xdm/protodpy.c b/xdm/protodpy.c
index 66d6213..b655e6f 100644
--- a/xdm/protodpy.c
+++ b/xdm/protodpy.c
@@ -105,10 +105,10 @@ NewProtoDisplay (
Debug ("NewProtoDisplay\n");
time (&date);
TimeoutProtoDisplays (date);
- pdpy = (struct protoDisplay *) malloc (sizeof *pdpy);
+ pdpy = malloc (sizeof *pdpy);
if (!pdpy)
return NULL;
- pdpy->address = (XdmcpNetaddr) malloc (addrlen);
+ pdpy->address = malloc (addrlen);
if (!pdpy->address)
{
free (pdpy);
diff --git a/xdm/resource.c b/xdm/resource.c
index a2050bd..ece4de3 100644
--- a/xdm/resource.c
+++ b/xdm/resource.c
@@ -403,7 +403,7 @@ ReinitResources (void)
char **argv;
XrmDatabase newDB;
- argv = (char **) malloc ((originalArgc + 1) * sizeof (char *));
+ argv = malloc ((originalArgc + 1) * sizeof (char *));
if (!argv)
LogPanic ("no space for argument realloc\n");
for (argc = 0; argc < originalArgc; argc++)
diff --git a/xdm/rpcauth.c b/xdm/rpcauth.c
index 2dc4d9d..6fb9a1e 100644
--- a/xdm/rpcauth.c
+++ b/xdm/rpcauth.c
@@ -57,7 +57,7 @@ SecureRPCGetAuth (
char key[MAXNETNAMELEN+1];
Xauth *new;
- new = (Xauth *) malloc (sizeof *new);
+ new = malloc (sizeof *new);
if (!new)
return (Xauth *) 0;
new->family = FamilyWild;
@@ -69,13 +69,13 @@ SecureRPCGetAuth (
getnetname (key);
Debug ("System netname %s\n", key);
new->data_length = strlen(key);
- new->data = (char *) malloc (new->data_length);
+ new->data = malloc (new->data_length);
if (!new->data)
{
free (new);
return (Xauth *) 0;
}
- new->name = (char *) malloc (namelen);
+ new->name = malloc (namelen);
if (!new->name)
{
free (new->data);
diff --git a/xdm/server.c b/xdm/server.c
index 0d69a8e..7fe55e6 100644
--- a/xdm/server.c
+++ b/xdm/server.c
@@ -265,7 +265,7 @@ GetRemoteAddress (struct display *d, int fd)
d->peerlen = 0;
if (len)
{
- d->peer = (XdmcpNetaddr) malloc (len);
+ d->peer = malloc (len);
if (d->peer)
{
memmove( (char *) d->peer, buf, len);
diff --git a/xdm/session.c b/xdm/session.c
index 71e0954..5fd47f0 100644
--- a/xdm/session.c
+++ b/xdm/session.c
@@ -985,7 +985,7 @@ execute (char **argv, char **environ)
for (av = argv, argc = 0; *av; av++, argc++)
/* SUPPRESS 530 */
;
- newargv = (char **) malloc ((argc + (optarg ? 3 : 2)) * sizeof (char *));
+ newargv = malloc ((argc + (optarg ? 3 : 2)) * sizeof (char *));
if (!newargv)
return;
av = newargv;
diff --git a/xdm/util.c b/xdm/util.c
index cf1075e..033633a 100644
--- a/xdm/util.c
+++ b/xdm/util.c
@@ -150,11 +150,11 @@ setEnv (char **e, char *name, char *value)
return e;
}
envsize = old - e;
- new = (char **) realloc ((char *) e,
+ new = realloc ((char *) e,
(unsigned) ((envsize + 2) * sizeof (char *)));
} else {
envsize = 0;
- new = (char **) malloc (2 * sizeof (char *));
+ new = malloc (2 * sizeof (char *));
}
if (!new) {
LogOutOfMem ("setEnv");
@@ -218,7 +218,7 @@ parseArgs (char **argv, char *string)
while (argv && argv[i])
++i;
if (!argv) {
- argv = (char **) malloc (sizeof (char *));
+ argv = malloc (sizeof (char *));
if (!argv) {
LogOutOfMem ("parseArgs");
return NULL;
@@ -228,7 +228,7 @@ parseArgs (char **argv, char *string)
for (;;) {
if (!*string || isblank (*string)) {
if (word != string) {
- newargv = (char **) realloc ((char *) argv,
+ newargv = realloc ((char *) argv,
(unsigned) ((i + 2) * sizeof (char *)));
save = malloc ((unsigned) (string - word + 1));
if (!newargv || !save) {
diff --git a/xdm/xdmauth.c b/xdm/xdmauth.c
index fbee684..4b945cf 100644
--- a/xdm/xdmauth.c
+++ b/xdm/xdmauth.c
@@ -84,7 +84,7 @@ static Xauth *
XdmGetAuthHelper (unsigned short namelen, char *name, int includeRho)
{
Xauth *new;
- new = (Xauth *) malloc (sizeof (Xauth));
+ new = malloc (sizeof (Xauth));
if (!new)
return (Xauth *) 0;
@@ -98,13 +98,13 @@ XdmGetAuthHelper (unsigned short namelen, char *name, int includeRho)
else
new->data_length = 8;
- new->data = (char *) malloc (new->data_length);
+ new->data = malloc (new->data_length);
if (!new->data)
{
free (new);
return (Xauth *) 0;
}
- new->name = (char *) malloc (namelen);
+ new->name = malloc (namelen);
if (!new->name)
{
free (new->data);
@@ -148,7 +148,7 @@ XdmGetXdmcpAuth (struct protoDisplay *pdpy,
xdmcpauth = XdmGetAuthHelper (authorizationNameLen, authorizationName, FALSE);
if (!xdmcpauth)
return;
- fileauth = (Xauth *) malloc (sizeof (Xauth));
+ fileauth = malloc (sizeof (Xauth));
if (!fileauth)
{
XauDisposeAuth(xdmcpauth);
diff --git a/xdm/xdmcp.c b/xdm/xdmcp.c
index 81be647..5bc4716 100644
--- a/xdm/xdmcp.c
+++ b/xdm/xdmcp.c
@@ -1232,7 +1232,7 @@ manage (
free (class);
class = (char *) NULL;
}
- from_save = (XdmcpNetaddr) malloc (fromlen);
+ from_save = malloc (fromlen);
if (!from_save)
{
send_failed (from, fromlen, name, sessionID,
@@ -1273,7 +1273,7 @@ manage (
XdmcpDisposeARRAY8 (&clientPort);
if (pdpy->fileAuthorization)
{
- d->authorizations = (Xauth **) malloc (sizeof (Xauth *));
+ d->authorizations = malloc (sizeof (Xauth *));
if (!d->authorizations)
{
free (from_save);
--
1.7.3.2
More information about the xorg-devel
mailing list