This is the last patch related to ticket
https://fedorahosted.org/sssd/ticket/1359
The warnings here are currently all false positives (refcount) or the alignment is calculated during runtime with PADDING_SIZE macro so this patch is just about silencing the compiler.
The patch is attached.
Michal
On (13/02/14 12:06), Michal Židek wrote:
This is the last patch related to ticket
https://fedorahosted.org/sssd/ticket/1359
The warnings here are currently all false positives (refcount) or the alignment is calculated during runtime with PADDING_SIZE macro so this patch is just about silencing the compiler.
The patch is attached.
Michal
From 7b57e5039038661e79e918bc253dc15f91fb78ea Mon Sep 17 00:00:00 2001 From: Michal Zidek mzidek@redhat.com Date: Thu, 13 Feb 2014 11:18:14 +0100 Subject: [PATCH] Suppress safealign warnings with DISCARD_ALIGN.
These warnings were all false positives (or the alignment is calculated during runtime).
fixes: https://fedorahosted.org/sssd/ticket/1359
src/sss_client/nss_group.c | 2 +- src/sss_client/nss_services.c | 2 +- src/util/refcount.c | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/sss_client/nss_group.c b/src/sss_client/nss_group.c index 9e25931..35838de 100644 --- a/src/sss_client/nss_group.c +++ b/src/sss_client/nss_group.c @@ -237,7 +237,7 @@ static int sss_nss_getgr_readrep(struct sss_nss_gr_rep *pr, pad = PADDING_SIZE(i, char *);
/* now members */
- pr->result->gr_mem = (char **)&(pr->buffer[i+pad]);
pr->result->gr_mem = (char **) DISCARD_ALIGN(&(pr->buffer[i+pad]));
ptmem = (sizeof(char *) * (mem_num + 1)) + pad; if (ptmem > dlen) {
diff --git a/src/sss_client/nss_services.c b/src/sss_client/nss_services.c index e89e0d2..902e14c 100644 --- a/src/sss_client/nss_services.c +++ b/src/sss_client/nss_services.c @@ -131,7 +131,7 @@ sss_nss_getsvc_readrep(struct sss_nss_svc_rep *sr, pad = PADDING_SIZE(i, char *);
/* Copy in the aliases */
- sr->result->s_aliases = (char **) &(sr->buffer[i+pad]);
sr->result->s_aliases = (char **) DISCARD_ALIGN(&(sr->buffer[i+pad]));
ptaliases = (sizeof(char *) * (num_aliases + 1)) + pad; if (ptaliases > dlen) {
diff --git a/src/util/refcount.c b/src/util/refcount.c index 735170d..5c454e7 100644 --- a/src/util/refcount.c +++ b/src/util/refcount.c @@ -48,6 +48,7 @@ _rc_alloc(const void *context, size_t size, size_t refcount_offset, const char *type_name) { struct wrapper *wrapper;
char *refcount_pos;
wrapper = talloc(context, struct wrapper); if (wrapper == NULL) {
@@ -60,7 +61,8 @@ _rc_alloc(const void *context, size_t size, size_t refcount_offset, return NULL; };
- wrapper->refcount = (int *)((char *)wrapper->ptr + refcount_offset);
refcount_pos = (char *)wrapper->ptr + refcount_offset;
wrapper->refcount = (int *) DISCARD_ALIGN(refcount_pos); *wrapper->refcount = 1;
talloc_set_destructor(wrapper, refcount_destructor);
@@ -72,6 +74,7 @@ void * _rc_reference(const void *context, size_t refcount_offset, void *source) { struct wrapper *wrapper;
char *refcount_pos;
wrapper = talloc(context, struct wrapper); if (wrapper == NULL) {
@@ -79,7 +82,8 @@ _rc_reference(const void *context, size_t refcount_offset, void *source) }
wrapper->ptr = source;
- wrapper->refcount = (int *)((char *)wrapper->ptr + refcount_offset);
- refcount_pos = (char *)wrapper->ptr + refcount_offset;
- wrapper->refcount = (int *) DISCARD_ALIGN(refcount_pos);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ It looks like macro DISCARD_ALIGN can be extended to in similar way like a talloc_zero(const void *ptr, #type);
LS
wrapper->ptr = source;
- wrapper->refcount = (int *)((char *)wrapper->ptr + refcount_offset);
- refcount_pos = (char *)wrapper->ptr + refcount_offset;
- wrapper->refcount = (int *) DISCARD_ALIGN(refcount_pos);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It looks like macro DISCARD_ALIGN can be extended to in similar way like a talloc_zero(const void *ptr, #type);
LS
Makes sense. Patch 2 adds this parameter.
Michal
On 02/13/2014 03:26 PM, Michal Židek wrote:
wrapper->ptr = source;
- wrapper->refcount = (int *)((char *)wrapper->ptr +
refcount_offset);
- refcount_pos = (char *)wrapper->ptr + refcount_offset;
- wrapper->refcount = (int *) DISCARD_ALIGN(refcount_pos);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It looks like macro DISCARD_ALIGN can be extended to in similar way like a talloc_zero(const void *ptr, #type);
LS
Makes sense. Patch 2 adds this parameter.
Michal
Rebased and added one patch for VTABLE_FUNC macro.
Michal
On (30/06/14 15:18), Michal Židek wrote:
On 02/13/2014 03:26 PM, Michal Židek wrote:
wrapper->ptr = source;
- wrapper->refcount = (int *)((char *)wrapper->ptr +
refcount_offset);
- refcount_pos = (char *)wrapper->ptr + refcount_offset;
- wrapper->refcount = (int *) DISCARD_ALIGN(refcount_pos);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It looks like macro DISCARD_ALIGN can be extended to in similar way like a talloc_zero(const void *ptr, #type);
LS
Makes sense. Patch 2 adds this parameter.
Michal
Rebased and added one patch for VTABLE_FUNC macro.
Michal
From e50c4a89a328a20118b86bea310b26aa83f7856a Mon Sep 17 00:00:00 2001 From: Michal Zidek mzidek@redhat.com Date: Thu, 13 Feb 2014 11:18:14 +0100 Subject: [PATCH 1/3] Suppress safealign warnings with DISCARD_ALIGN.
These warnings were all false positives (or the alignment is calculated during runtime).
fixes: https://fedorahosted.org/sssd/ticket/1359
src/sss_client/nss_group.c | 2 +- src/sss_client/nss_services.c | 2 +- src/util/refcount.c | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/sss_client/nss_group.c b/src/sss_client/nss_group.c index 9e25931..35838de 100644 --- a/src/sss_client/nss_group.c +++ b/src/sss_client/nss_group.c @@ -237,7 +237,7 @@ static int sss_nss_getgr_readrep(struct sss_nss_gr_rep *pr, pad = PADDING_SIZE(i, char *);
/* now members */
- pr->result->gr_mem = (char **)&(pr->buffer[i+pad]);
pr->result->gr_mem = (char **) DISCARD_ALIGN(&(pr->buffer[i+pad]));
ptmem = (sizeof(char *) * (mem_num + 1)) + pad; if (ptmem > dlen) {
diff --git a/src/sss_client/nss_services.c b/src/sss_client/nss_services.c index e89e0d2..902e14c 100644 --- a/src/sss_client/nss_services.c +++ b/src/sss_client/nss_services.c @@ -131,7 +131,7 @@ sss_nss_getsvc_readrep(struct sss_nss_svc_rep *sr, pad = PADDING_SIZE(i, char *);
/* Copy in the aliases */
- sr->result->s_aliases = (char **) &(sr->buffer[i+pad]);
sr->result->s_aliases = (char **) DISCARD_ALIGN(&(sr->buffer[i+pad]));
ptaliases = (sizeof(char *) * (num_aliases + 1)) + pad; if (ptaliases > dlen) {
diff --git a/src/util/refcount.c b/src/util/refcount.c index 735170d..5c454e7 100644 --- a/src/util/refcount.c +++ b/src/util/refcount.c @@ -48,6 +48,7 @@ _rc_alloc(const void *context, size_t size, size_t refcount_offset, const char *type_name) { struct wrapper *wrapper;
char *refcount_pos;
wrapper = talloc(context, struct wrapper); if (wrapper == NULL) {
@@ -60,7 +61,8 @@ _rc_alloc(const void *context, size_t size, size_t refcount_offset, return NULL; };
- wrapper->refcount = (int *)((char *)wrapper->ptr + refcount_offset);
refcount_pos = (char *)wrapper->ptr + refcount_offset;
wrapper->refcount = (int *) DISCARD_ALIGN(refcount_pos); *wrapper->refcount = 1;
talloc_set_destructor(wrapper, refcount_destructor);
@@ -72,6 +74,7 @@ void * _rc_reference(const void *context, size_t refcount_offset, void *source) { struct wrapper *wrapper;
char *refcount_pos;
wrapper = talloc(context, struct wrapper); if (wrapper == NULL) {
@@ -79,7 +82,8 @@ _rc_reference(const void *context, size_t refcount_offset, void *source) }
wrapper->ptr = source;
- wrapper->refcount = (int *)((char *)wrapper->ptr + refcount_offset);
refcount_pos = (char *)wrapper->ptr + refcount_offset;
wrapper->refcount = (int *) DISCARD_ALIGN(refcount_pos); (*wrapper->refcount)++;
talloc_set_destructor(wrapper, refcount_destructor);
-- 1.7.11.2
From ee49d174b745719cc5a1848b0296af7c87d57894 Mon Sep 17 00:00:00 2001 From: Michal Zidek mzidek@redhat.com Date: Thu, 13 Feb 2014 14:50:57 +0100 Subject: [PATCH 2/3] Add type parameter to DISCARD_ALIGN
src/sss_client/nss_group.c | 2 +- src/sss_client/nss_mc_group.c | 2 +- src/sss_client/nss_services.c | 2 +- src/util/refcount.c | 4 ++-- src/util/util_safealign.h | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/sss_client/nss_group.c b/src/sss_client/nss_group.c index 35838de..1614c33 100644 --- a/src/sss_client/nss_group.c +++ b/src/sss_client/nss_group.c @@ -237,7 +237,7 @@ static int sss_nss_getgr_readrep(struct sss_nss_gr_rep *pr, pad = PADDING_SIZE(i, char *);
/* now members */
- pr->result->gr_mem = (char **) DISCARD_ALIGN(&(pr->buffer[i+pad]));
pr->result->gr_mem = DISCARD_ALIGN(&(pr->buffer[i+pad]), char **);
ptmem = (sizeof(char *) * (mem_num + 1)) + pad; if (ptmem > dlen) {
diff --git a/src/sss_client/nss_mc_group.c b/src/sss_client/nss_mc_group.c index fb5e43f..5af5546 100644 --- a/src/sss_client/nss_mc_group.c +++ b/src/sss_client/nss_mc_group.c @@ -72,7 +72,7 @@ static errno_t sss_nss_mc_parse_result(struct sss_mc_rec *rec, return EFAULT; }
- result->gr_mem = (char **)DISCARD_ALIGN(buffer);
- result->gr_mem = DISCARD_ALIGN(buffer, char **); result->gr_mem[data->members] = NULL;
You changed the same lines in two different patches. patches would be simpler with different order of changes.
1st change DISCARD_ALIGN macro -#define DISCARD_ALIGN(ptr) ((void *)(ptr)) +#define DISCARD_ALIGN(ptr, type) ((type)(void *)(ptr))
2nd use macro DISCARD_ALIGN where appropriate.
LS
On 06/30/2014 03:33 PM, Lukas Slebodnik wrote:
On (30/06/14 15:18), Michal Židek wrote:
On 02/13/2014 03:26 PM, Michal Židek wrote:
wrapper->ptr = source;
- wrapper->refcount = (int *)((char *)wrapper->ptr +
refcount_offset);
- refcount_pos = (char *)wrapper->ptr + refcount_offset;
- wrapper->refcount = (int *) DISCARD_ALIGN(refcount_pos);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It looks like macro DISCARD_ALIGN can be extended to in similar way like a talloc_zero(const void *ptr, #type);
LS
Makes sense. Patch 2 adds this parameter.
Michal
Rebased and added one patch for VTABLE_FUNC macro.
Michal
From e50c4a89a328a20118b86bea310b26aa83f7856a Mon Sep 17 00:00:00 2001 From: Michal Zidek mzidek@redhat.com Date: Thu, 13 Feb 2014 11:18:14 +0100 Subject: [PATCH 1/3] Suppress safealign warnings with DISCARD_ALIGN.
These warnings were all false positives (or the alignment is calculated during runtime).
fixes: https://fedorahosted.org/sssd/ticket/1359
src/sss_client/nss_group.c | 2 +- src/sss_client/nss_services.c | 2 +- src/util/refcount.c | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/sss_client/nss_group.c b/src/sss_client/nss_group.c index 9e25931..35838de 100644 --- a/src/sss_client/nss_group.c +++ b/src/sss_client/nss_group.c @@ -237,7 +237,7 @@ static int sss_nss_getgr_readrep(struct sss_nss_gr_rep *pr, pad = PADDING_SIZE(i, char *);
/* now members */
- pr->result->gr_mem = (char **)&(pr->buffer[i+pad]);
pr->result->gr_mem = (char **) DISCARD_ALIGN(&(pr->buffer[i+pad]));
ptmem = (sizeof(char *) * (mem_num + 1)) + pad; if (ptmem > dlen) {
diff --git a/src/sss_client/nss_services.c b/src/sss_client/nss_services.c index e89e0d2..902e14c 100644 --- a/src/sss_client/nss_services.c +++ b/src/sss_client/nss_services.c @@ -131,7 +131,7 @@ sss_nss_getsvc_readrep(struct sss_nss_svc_rep *sr, pad = PADDING_SIZE(i, char *);
/* Copy in the aliases */
- sr->result->s_aliases = (char **) &(sr->buffer[i+pad]);
sr->result->s_aliases = (char **) DISCARD_ALIGN(&(sr->buffer[i+pad]));
ptaliases = (sizeof(char *) * (num_aliases + 1)) + pad; if (ptaliases > dlen) {
diff --git a/src/util/refcount.c b/src/util/refcount.c index 735170d..5c454e7 100644 --- a/src/util/refcount.c +++ b/src/util/refcount.c @@ -48,6 +48,7 @@ _rc_alloc(const void *context, size_t size, size_t refcount_offset, const char *type_name) { struct wrapper *wrapper;
char *refcount_pos;
wrapper = talloc(context, struct wrapper); if (wrapper == NULL) {
@@ -60,7 +61,8 @@ _rc_alloc(const void *context, size_t size, size_t refcount_offset, return NULL; };
- wrapper->refcount = (int *)((char *)wrapper->ptr + refcount_offset);
refcount_pos = (char *)wrapper->ptr + refcount_offset;
wrapper->refcount = (int *) DISCARD_ALIGN(refcount_pos); *wrapper->refcount = 1;
talloc_set_destructor(wrapper, refcount_destructor);
@@ -72,6 +74,7 @@ void * _rc_reference(const void *context, size_t refcount_offset, void *source) { struct wrapper *wrapper;
char *refcount_pos;
wrapper = talloc(context, struct wrapper); if (wrapper == NULL) {
@@ -79,7 +82,8 @@ _rc_reference(const void *context, size_t refcount_offset, void *source) }
wrapper->ptr = source;
- wrapper->refcount = (int *)((char *)wrapper->ptr + refcount_offset);
refcount_pos = (char *)wrapper->ptr + refcount_offset;
wrapper->refcount = (int *) DISCARD_ALIGN(refcount_pos); (*wrapper->refcount)++;
talloc_set_destructor(wrapper, refcount_destructor);
-- 1.7.11.2
From ee49d174b745719cc5a1848b0296af7c87d57894 Mon Sep 17 00:00:00 2001 From: Michal Zidek mzidek@redhat.com Date: Thu, 13 Feb 2014 14:50:57 +0100 Subject: [PATCH 2/3] Add type parameter to DISCARD_ALIGN
src/sss_client/nss_group.c | 2 +- src/sss_client/nss_mc_group.c | 2 +- src/sss_client/nss_services.c | 2 +- src/util/refcount.c | 4 ++-- src/util/util_safealign.h | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/src/sss_client/nss_group.c b/src/sss_client/nss_group.c index 35838de..1614c33 100644 --- a/src/sss_client/nss_group.c +++ b/src/sss_client/nss_group.c @@ -237,7 +237,7 @@ static int sss_nss_getgr_readrep(struct sss_nss_gr_rep *pr, pad = PADDING_SIZE(i, char *);
/* now members */
- pr->result->gr_mem = (char **) DISCARD_ALIGN(&(pr->buffer[i+pad]));
pr->result->gr_mem = DISCARD_ALIGN(&(pr->buffer[i+pad]), char **);
ptmem = (sizeof(char *) * (mem_num + 1)) + pad; if (ptmem > dlen) {
diff --git a/src/sss_client/nss_mc_group.c b/src/sss_client/nss_mc_group.c index fb5e43f..5af5546 100644 --- a/src/sss_client/nss_mc_group.c +++ b/src/sss_client/nss_mc_group.c @@ -72,7 +72,7 @@ static errno_t sss_nss_mc_parse_result(struct sss_mc_rec *rec, return EFAULT; }
- result->gr_mem = (char **)DISCARD_ALIGN(buffer);
- result->gr_mem = DISCARD_ALIGN(buffer, char **); result->gr_mem[data->members] = NULL;
You changed the same lines in two different patches. patches would be simpler with different order of changes.
1st change DISCARD_ALIGN macro -#define DISCARD_ALIGN(ptr) ((void *)(ptr)) +#define DISCARD_ALIGN(ptr, type) ((type)(void *)(ptr))
2nd use macro DISCARD_ALIGN where appropriate.
LS
Ok. Now it is in more sane order.
Michal
On (30/06/14 16:36), Michal Židek wrote:
On 06/30/2014 03:33 PM, Lukas Slebodnik wrote:
On (30/06/14 15:18), Michal Židek wrote:
On 02/13/2014 03:26 PM, Michal Židek wrote:
wrapper->ptr = source;
- wrapper->refcount = (int *)((char *)wrapper->ptr +
refcount_offset);
- refcount_pos = (char *)wrapper->ptr + refcount_offset;
- wrapper->refcount = (int *) DISCARD_ALIGN(refcount_pos);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
It looks like macro DISCARD_ALIGN can be extended to in similar way like a talloc_zero(const void *ptr, #type);
LS
Makes sense. Patch 2 adds this parameter.
Michal
Rebased and added one patch for VTABLE_FUNC macro.
Michal
3x ACK
LS
On Mon, Jun 30, 2014 at 04:59:16PM +0200, Lukas Slebodnik wrote:
On (30/06/14 16:36), Michal Židek wrote:
On 06/30/2014 03:33 PM, Lukas Slebodnik wrote:
On (30/06/14 15:18), Michal Židek wrote:
On 02/13/2014 03:26 PM, Michal Židek wrote:
> wrapper->ptr = source; >- wrapper->refcount = (int *)((char *)wrapper->ptr + >refcount_offset); >+ refcount_pos = (char *)wrapper->ptr + refcount_offset; >+ wrapper->refcount = (int *) DISCARD_ALIGN(refcount_pos); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ It looks like macro DISCARD_ALIGN can be extended to in similar way like a talloc_zero(const void *ptr, #type);
LS
Makes sense. Patch 2 adds this parameter.
Michal
Rebased and added one patch for VTABLE_FUNC macro.
Michal
3x ACK
LS
Finally my Raspberry will compile SSSD w/o warnings :-)
Pushed to master: 0f495aa73529b06b0a8b4c39cfd098351c4f6760 684405758a96bd9fb47480d44f2e1a2f038f8def 90ac46f71068d131391492360a8553bdd005b5a7
sssd-devel@lists.fedorahosted.org