From f4d878086e653ff31deeb31b9121f6b7bd01d901 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Wed, 17 Jul 2024 12:27:18 +0200 Subject: [PATCH] Xext: selinux: use static reply struct init on declaration Make the code a bit easier to read by using initialization of the reply structs, at the point of declaration. Most of them aren't written to later, just passed into WriteReplyToClient(). Also dropping some useless zero assignments (struct initializers automatically zero-out unmentioned fields). Signed-off-by: Enrico Weigelt, metux IT consult Part-of: --- Xext/xselinux_ext.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/Xext/xselinux_ext.c b/Xext/xselinux_ext.c index 407c43570..dd5ace348 100644 --- a/Xext/xselinux_ext.c +++ b/Xext/xselinux_ext.c @@ -70,7 +70,6 @@ ProcSELinuxQueryVersion(ClientPtr client) SELinuxQueryVersionReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, - .length = 0, .server_major = SELINUX_MAJOR_VERSION, .server_minor = SELINUX_MINOR_VERSION }; @@ -87,7 +86,6 @@ ProcSELinuxQueryVersion(ClientPtr client) static int SELinuxSendContextReply(ClientPtr client, security_id_t sid) { - SELinuxGetContextReply rep; char *ctx = NULL; int len = 0; @@ -97,7 +95,7 @@ SELinuxSendContextReply(ClientPtr client, security_id_t sid) len = strlen(ctx) + 1; } - rep = (SELinuxGetContextReply) { + SELinuxGetContextReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, .length = bytes_to_int32(len), @@ -344,13 +342,9 @@ static int SELinuxSendItemsToClient(ClientPtr client, SELinuxListItemRec * items, int size, int count) { - int rc, k, pos = 0; - SELinuxListItemsReply rep; - CARD32 *buf; - - buf = calloc(size, sizeof(CARD32)); + int rc = BadAlloc, k, pos = 0; + CARD32 *buf = calloc(size, sizeof(CARD32)); if (size && !buf) { - rc = BadAlloc; goto out; } @@ -378,7 +372,7 @@ SELinuxSendItemsToClient(ClientPtr client, SELinuxListItemRec * items, } /* Send reply to client */ - rep = (SELinuxListItemsReply) { + SELinuxListItemsReply rep = { .type = X_Reply, .sequenceNumber = client->sequence, .length = size,