gpgsm: Fix alignment
NIIBE Yutaka
gniibe at fsij.org
Wed Sep 14 09:04:32 CEST 2016
Hello, Justus,
On armhf architecture, I got this warning with gcc-6:
==================
../../../gnupg/tests/gpgscm/scheme.c: In function ‘alloc_cellseg’:
../../../gnupg/tests/gpgscm/scheme.c:627:15: warning: cast increases
required alignment of target type [-Wcast-align]
newp=(pointer)cp;
^
==================
I think that with modern C, we use (void *) for address. (char *) is
specifically for character where its alignment is 1.
How about this fix?
diff --git a/tests/gpgscm/scheme-private.h b/tests/gpgscm/scheme-private.h
index 9eafe76..727e0c0 100644
--- a/tests/gpgscm/scheme-private.h
+++ b/tests/gpgscm/scheme-private.h
@@ -78,7 +78,7 @@ int tracing;
#ifndef CELL_NSEGMENT
#define CELL_NSEGMENT 10 /* # of segments for cells */
#endif
-char *alloc_seg[CELL_NSEGMENT];
+void *alloc_seg[CELL_NSEGMENT];
pointer cell_seg[CELL_NSEGMENT];
int last_cell_seg;
diff --git a/tests/gpgscm/scheme.c b/tests/gpgscm/scheme.c
index 1fc7643..8833950 100644
--- a/tests/gpgscm/scheme.c
+++ b/tests/gpgscm/scheme.c
@@ -602,7 +602,7 @@ static int alloc_cellseg(scheme *sc, int n) {
pointer newp;
pointer last;
pointer p;
- char *cp;
+ void *cp;
long i;
int k;
int adj=ADJ;
@@ -614,14 +614,14 @@ static int alloc_cellseg(scheme *sc, int n) {
for (k = 0; k < n; k++) {
if (sc->last_cell_seg >= CELL_NSEGMENT - 1)
return k;
- cp = (char*) sc->malloc(CELL_SEGSIZE * sizeof(struct cell)+adj);
+ cp = sc->malloc(CELL_SEGSIZE * sizeof(struct cell)+adj);
if (cp == 0)
return k;
i = ++sc->last_cell_seg ;
sc->alloc_seg[i] = cp;
/* adjust in TYPE_BITS-bit boundary */
if(((unsigned long)cp)%adj!=0) {
- cp=(char*)(adj*((unsigned long)cp/adj+1));
+ cp=(void *)(adj*((unsigned long)cp/adj+1));
}
/* insert new segment in address order */
newp=(pointer)cp;
--
More information about the Gnupg-devel
mailing list