[Pkg-gnupg-commit] [gnupg1] 05/35: g10: Fix iobuf API of filter function for alignment.

Daniel Kahn Gillmor dkg at fifthhorseman.net
Mon Aug 29 14:48:36 UTC 2016


This is an automated email from the git hooks/post-receive script.

dkg pushed a commit to branch master
in repository gnupg1.

commit aa4a3aa3e7a0c7dc231b90b2958184c7138ccc93
Author: NIIBE Yutaka <gniibe at fsij.org>
Date:   Tue Jan 26 15:38:27 2016 +0900

    g10: Fix iobuf API of filter function for alignment.
    
    * include/iobuf.h (struct iobuf_struct): Remove DESC.
    * util/iobuf.c (iobuf_desc): New.
    (print_chain, iobuf_close, iobuf_open, iobuf_fdopen, iobuf_sockopen)
    (iobuf_create, iobuf_append, iobuf_openrw, iobuf_ioctl)
    (iobuf_push_filter2, pop_filter, underflow): Use iobuf_desc.
    (file_filter, sock_filter, block_filter): Fill the description.
    * g10/armor.c, g10/cipher.c, g10/compress-bz2.c, g10/compress.c,
    g10/encode.c, g10/encr-data.c, g10/mdfilter.c, g10/pipemode.c,
    g10/progress.c, g10/textfilter.c: Likewise.
    
    --
    
    Newer GCC warns against possible alignment difference of pointers.
    This change can silence those warnings.
    
    Signed-off-by: NIIBE Yutaka <gniibe at fsij.org>
    
    (backported from 2.1 commit 3f52c7da3940ec06572270d511000dc7fe9c27d2)
---
 g10/armor.c        |  2 +-
 g10/cipher.c       |  2 +-
 g10/compress-bz2.c |  2 +-
 g10/compress.c     |  2 +-
 g10/encode.c       |  2 +-
 g10/encr-data.c    |  4 +--
 g10/mdfilter.c     |  2 +-
 g10/pipemode.c     |  2 +-
 g10/progress.c     |  2 +-
 g10/textfilter.c   |  2 +-
 include/iobuf.h    |  1 -
 util/iobuf.c       | 74 +++++++++++++++++++++++++++++++++---------------------
 12 files changed, 56 insertions(+), 41 deletions(-)

diff --git a/g10/armor.c b/g10/armor.c
index be03692..1ae3c60 100644
--- a/g10/armor.c
+++ b/g10/armor.c
@@ -1300,7 +1300,7 @@ armor_filter( void *opaque, int control,
         release_armor_context (afx);
     }
     else if( control == IOBUFCTRL_DESC )
-	*(char**)buf = "armor_filter";
+        mem2str (buf, "armor_filter", *ret_len);
     return rc;
 }
 
diff --git a/g10/cipher.c b/g10/cipher.c
index 0c51100..45e1963 100644
--- a/g10/cipher.c
+++ b/g10/cipher.c
@@ -145,7 +145,7 @@ cipher_filter( void *opaque, int control,
 	cipher_close(cfx->cipher_hd);
     }
     else if( control == IOBUFCTRL_DESC ) {
-	*(char**)buf = "cipher_filter";
+        mem2str (buf, "cipher_filter", *ret_len);
     }
     return rc;
 }
diff --git a/g10/compress-bz2.c b/g10/compress-bz2.c
index baef92f..6c5bd66 100644
--- a/g10/compress-bz2.c
+++ b/g10/compress-bz2.c
@@ -247,6 +247,6 @@ compress_filter_bz2( void *opaque, int control,
 	zfx->release (zfx);
     }
   else if( control == IOBUFCTRL_DESC )
-    *(char**)buf = "compress_filter";
+    mem2str (buf, "compress_filter", *ret_len);
   return rc;
 }
diff --git a/g10/compress.c b/g10/compress.c
index 07c9e5e..4598aff 100644
--- a/g10/compress.c
+++ b/g10/compress.c
@@ -295,7 +295,7 @@ compress_filter( void *opaque, int control,
           zfx->release (zfx);
     }
     else if( control == IOBUFCTRL_DESC )
-	*(char**)buf = "compress_filter";
+        mem2str (buf, "compress_filter", *ret_len);
     return rc;
 }
 
diff --git a/g10/encode.c b/g10/encode.c
index a579c42..93c70a7 100644
--- a/g10/encode.c
+++ b/g10/encode.c
@@ -736,7 +736,7 @@ encrypt_filter( void *opaque, int control,
 	xfree(efx->symkey_s2k);
       }
     else if( control == IOBUFCTRL_DESC ) {
-	*(char**)buf = "encrypt_filter";
+        mem2str (buf, "encrypt_filter", *ret_len);
     }
     return rc;
 }
diff --git a/g10/encr-data.c b/g10/encr-data.c
index c65aa11..baa0606 100644
--- a/g10/encr-data.c
+++ b/g10/encr-data.c
@@ -300,7 +300,7 @@ mdc_decode_filter( void *opaque, int control, IOBUF a,
         release_dfx_context (dfx);
     }
     else if( control == IOBUFCTRL_DESC ) {
-	*(char**)buf = "mdc_decode_filter";
+        mem2str (buf, "mdc_decode_filter", *ret_len);
     }
     return rc;
 }
@@ -329,7 +329,7 @@ decode_filter( void *opaque, int control, IOBUF a, byte *buf, size_t *ret_len)
         release_dfx_context (fc);
     }
     else if( control == IOBUFCTRL_DESC ) {
-	*(char**)buf = "decode_filter";
+        mem2str (buf, "decode_filter", *ret_len);
     }
     return rc;
 }
diff --git a/g10/mdfilter.c b/g10/mdfilter.c
index 9c0059e..bb47f98 100644
--- a/g10/mdfilter.c
+++ b/g10/mdfilter.c
@@ -58,7 +58,7 @@ md_filter( void *opaque, int control,
 	*ret_len = i;
     }
     else if( control == IOBUFCTRL_DESC )
-	*(char**)buf = "md_filter";
+        mem2str (buf, "md_filter", *ret_len);
     return rc;
 }
 
diff --git a/g10/pipemode.c b/g10/pipemode.c
index 077f967..60c8020 100644
--- a/g10/pipemode.c
+++ b/g10/pipemode.c
@@ -281,7 +281,7 @@ pipemode_filter( void *opaque, int control,
 	*ret_len = n;
     }
     else if( control == IOBUFCTRL_DESC )
-	*(char**)buf = "pipemode_filter";
+        mem2str (buf, "pipemode_filter", *ret_len);
     return rc;
 }
 
diff --git a/g10/progress.c b/g10/progress.c
index 8c8265f..cea080c 100644
--- a/g10/progress.c
+++ b/g10/progress.c
@@ -91,7 +91,7 @@ progress_filter (void *opaque, int control,
       pfx->what = NULL;
     }
   else if (control == IOBUFCTRL_DESC)
-    *(char**)buf = "progress_filter";
+      mem2str (buf, "progress_filter", *ret_len);
   return rc;
 }
 
diff --git a/g10/textfilter.c b/g10/textfilter.c
index dc72a56..79f2f67 100644
--- a/g10/textfilter.c
+++ b/g10/textfilter.c
@@ -150,7 +150,7 @@ text_filter( void *opaque, int control,
 	tfx->buffer = NULL;
     }
     else if( control == IOBUFCTRL_DESC )
-	*(char**)buf = "text_filter";
+        mem2str (buf, "text_filter", *ret_len);
     return rc;
 }
 
diff --git a/include/iobuf.h b/include/iobuf.h
index 9515a0e..030f8c8 100644
--- a/include/iobuf.h
+++ b/include/iobuf.h
@@ -59,7 +59,6 @@ struct iobuf_struct {
     char *real_fname;
     IOBUF chain;	/* next iobuf used for i/o if any (passed to filter) */
     int no, subno;
-    const char *desc;
     void *opaque;      /* can be used to hold any information	 */
 		       /* this value is copied to all instances */
     struct {
diff --git a/util/iobuf.c b/util/iobuf.c
index a330460..539356e 100644
--- a/util/iobuf.c
+++ b/util/iobuf.c
@@ -459,7 +459,7 @@ file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
         a->keep_open = a->no_cache = 0;
     }
     else if( control == IOBUFCTRL_DESC ) {
-	*(char**)buf = "file_filter";
+        mem2str (buf, "file_filter", *ret_len);
     }
     else if( control == IOBUFCTRL_FREE ) {
 	if( f != stdin && f != stdout ) {
@@ -572,7 +572,7 @@ file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
         a->no_cache = 0;
     }
     else if ( control == IOBUFCTRL_DESC ) {
-	*(char**)buf = "file_filter(fd)";
+        mem2str (buf, "file_filter(fd)", *ret_len);
     }
     else if ( control == IOBUFCTRL_FREE ) {
 #ifdef HAVE_DOSISH_SYSTEM
@@ -660,7 +660,7 @@ sock_filter (void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
         a->no_cache = 0;
     }
     else if ( control == IOBUFCTRL_DESC ) {
-	*(char**)buf = "sock_filter";
+        mem2str (buf, "sock_filter", *ret_len);
     }
     else if ( control == IOBUFCTRL_FREE ) {
         if (!a->keep_open)
@@ -852,7 +852,7 @@ block_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
 	a->buflen = 0;
     }
     else if( control == IOBUFCTRL_DESC ) {
-	*(char**)buf = "block_filter";
+        mem2str (buf, "block_filter", *ret_len);
     }
     else if( control == IOBUFCTRL_FREE ) {
 	if( a->use == 2 ) { /* write the end markers */
@@ -906,6 +906,24 @@ block_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
     return rc;
 }
 
+#define MAX_IOBUF_DESC 32
+/*
+ * Fill the buffer by the description of iobuf A.
+ * The buffer size should be MAX_IOBUF_DESC (or larger).
+ * Returns BUF as (const char *).
+ */
+static const char *
+iobuf_desc (iobuf_t a, byte *buf)
+{
+  size_t len = MAX_IOBUF_DESC;
+
+  if (! a || ! a->filter)
+    memcpy (buf, "?", 2);
+  else
+    a->filter (a->filter_ov, IOBUFCTRL_DESC, NULL, buf, &len);
+
+  return buf;
+}
 
 static void
 print_chain( IOBUF a )
@@ -913,16 +931,11 @@ print_chain( IOBUF a )
     if( !DBG_IOBUF )
 	return;
     for(; a; a = a->chain ) {
-	size_t dummy_len = 0;
-	const char *desc = "[none]";
-
-	if( a->filter )
-	    a->filter( a->filter_ov, IOBUFCTRL_DESC, NULL,
-						(byte*)&desc, &dummy_len );
+        byte desc[MAX_IOBUF_DESC];
 
 	log_debug("iobuf chain: %d.%d `%s' filter_eof=%d start=%d len=%d\n",
-		   a->no, a->subno, desc?desc:"?", a->filter_eof,
-		   (int)a->d.start, (int)a->d.len );
+		  a->no, a->subno, iobuf_desc (a, desc), a->filter_eof,
+		  (int)a->d.start, (int)a->d.len );
     }
 }
 
@@ -971,13 +984,14 @@ iobuf_close ( IOBUF a )
     }
 
     for( ; a && !rc ; a = a2 ) {
+        byte desc[MAX_IOBUF_DESC];
 	a2 = a->chain;
 	if( a->use == 2 && (rc=iobuf_flush(a)) )
 	    log_error("iobuf_flush failed on close: %s\n", g10_errstr(rc));
 
 	if( DBG_IOBUF )
 	    log_debug("iobuf-%d.%d: close `%s'\n", a->no, a->subno,
-                      a->desc?a->desc:"?");
+                      iobuf_desc (a, desc));
 	if( a->filter && (rc = a->filter(a->filter_ov, IOBUFCTRL_FREE,
 					 a->chain, NULL, &dummy_len)) )
 	    log_error("IOBUFCTRL_FREE failed on close: %s\n", g10_errstr(rc) );
@@ -1132,7 +1146,6 @@ iobuf_open( const char *fname )
 	a->real_fname = xstrdup( fname );
     a->filter = file_filter;
     a->filter_ov = fcx;
-    file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len );
     file_filter( fcx, IOBUFCTRL_INIT, NULL, NULL, &len );
     if( DBG_IOBUF )
 	log_debug("iobuf-%d.%d: open `%s' fd=%d\n",
@@ -1166,7 +1179,6 @@ iobuf_fdopen( int fd, const char *mode )
     sprintf(fcx->fname, "[fd %d]", fd );
     a->filter = file_filter;
     a->filter_ov = fcx;
-    file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len );
     file_filter( fcx, IOBUFCTRL_INIT, NULL, NULL, &len );
     if( DBG_IOBUF )
 	log_debug("iobuf-%d.%d: fdopen `%s'\n", a->no, a->subno, fcx->fname );
@@ -1190,7 +1202,6 @@ iobuf_sockopen ( int fd, const char *mode )
     sprintf(scx->fname, "[sock %d]", fd );
     a->filter = sock_filter;
     a->filter_ov = scx;
-    sock_filter( scx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len );
     sock_filter( scx, IOBUFCTRL_INIT, NULL, NULL, &len );
     if( DBG_IOBUF )
 	log_debug("iobuf-%d.%d: sockopen `%s'\n", a->no, a->subno, scx->fname);
@@ -1213,6 +1224,7 @@ iobuf_create( const char *fname )
     size_t len;
     int print_only = 0;
     int fd;
+    byte desc[MAX_IOBUF_DESC];
 
     if( !fname || (*fname=='-' && !fname[1]) ) {
 	fp = FILEP_OR_FD_FOR_STDOUT;
@@ -1235,11 +1247,10 @@ iobuf_create( const char *fname )
 	a->real_fname = xstrdup( fname );
     a->filter = file_filter;
     a->filter_ov = fcx;
-    file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len );
     file_filter( fcx, IOBUFCTRL_INIT, NULL, NULL, &len );
     if( DBG_IOBUF )
 	log_debug("iobuf-%d.%d: create `%s'\n", a->no, a->subno,
-                  a->desc?a->desc:"?" );
+                  iobuf_desc (a, desc));
 
     return a;
 }
@@ -1257,6 +1268,7 @@ iobuf_append( const char *fname )
     FILE *fp;
     file_filter_ctx_t *fcx;
     size_t len;
+    byte desc[MAX_IOBUF_DESC];
 
     if( !fname )
 	return NULL;
@@ -1269,11 +1281,10 @@ iobuf_append( const char *fname )
     a->real_fname = xstrdup( fname );
     a->filter = file_filter;
     a->filter_ov = fcx;
-    file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len );
     file_filter( fcx, IOBUFCTRL_INIT, NULL, NULL, &len );
     if( DBG_IOBUF )
 	log_debug("iobuf-%d.%d: append `%s'\n", a->no, a->subno,
-                  a->desc?a->desc:"?" );
+                  iobuf_desc (a, desc));
 
     return a;
 }
@@ -1286,6 +1297,7 @@ iobuf_openrw( const char *fname )
     FILEP_OR_FD fp;
     file_filter_ctx_t *fcx;
     size_t len;
+    byte desc[MAX_IOBUF_DESC];
 
     if( !fname )
 	return NULL;
@@ -1298,11 +1310,10 @@ iobuf_openrw( const char *fname )
     a->real_fname = xstrdup( fname );
     a->filter = file_filter;
     a->filter_ov = fcx;
-    file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len );
     file_filter( fcx, IOBUFCTRL_INIT, NULL, NULL, &len );
     if( DBG_IOBUF )
 	log_debug("iobuf-%d.%d: openrw `%s'\n", a->no, a->subno,
-                  a->desc?a->desc:"?");
+                  iobuf_desc (a, desc));
 
     return a;
 }
@@ -1311,11 +1322,13 @@ iobuf_openrw( const char *fname )
 int
 iobuf_ioctl ( IOBUF a, int cmd, int intval, void *ptrval )
 {
+    byte desc[MAX_IOBUF_DESC];
+
     if ( cmd == 1 ) {  /* keep system filepointer/descriptor open */
         if( DBG_IOBUF )
             log_debug("iobuf-%d.%d: ioctl `%s' keep=%d\n",
                       a? a->no:-1, a?a->subno:-1,
-                      a&&a->desc?a->desc:"?", intval );
+                      iobuf_desc (a, desc), intval );
         for( ; a; a = a->chain )
             if( !a->chain && a->filter == file_filter ) {
                 file_filter_ctx_t *b = a->filter_ov;
@@ -1345,7 +1358,7 @@ iobuf_ioctl ( IOBUF a, int cmd, int intval, void *ptrval )
         if( DBG_IOBUF )
             log_debug("iobuf-%d.%d: ioctl `%s' no_cache=%d\n",
                       a? a->no:-1, a?a->subno:-1,
-                      a&&a->desc?a->desc:"?", intval );
+                      iobuf_desc (a, desc), intval );
         for( ; a; a = a->chain )
             if( !a->chain && a->filter == file_filter ) {
                 file_filter_ctx_t *b = a->filter_ov;
@@ -1457,11 +1470,12 @@ iobuf_push_filter2( IOBUF a,
     a->filter_ov_owner = rel_ov;
 
     a->subno = b->subno + 1;
-    f( ov, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &dummy_len );
 
     if( DBG_IOBUF ) {
+        byte desc[MAX_IOBUF_DESC];
+
 	log_debug("iobuf-%d.%d: push `%s'\n", a->no, a->subno,
-                  a->desc?a->desc:"?" );
+                  iobuf_desc (a, desc));
 	print_chain( a );
     }
 
@@ -1482,13 +1496,14 @@ pop_filter( IOBUF a, int (*f)(void *opaque, int control,
     IOBUF b;
     size_t dummy_len=0;
     int rc=0;
+    byte desc[MAX_IOBUF_DESC];
 
     if( a->directfp )
 	BUG();
 
     if( DBG_IOBUF )
 	log_debug("iobuf-%d.%d: pop `%s'\n", a->no, a->subno,
-                  a->desc?a->desc:"?" );
+                  iobuf_desc (a, desc));
     if( !a->filter ) { /* this is simple */
 	b = a->chain;
 	assert(b);
@@ -1563,10 +1578,12 @@ underflow(IOBUF a)
 
     if( a->filter_eof ) {
 	if( a->chain ) {
+            byte desc[MAX_IOBUF_DESC];
+
 	    IOBUF b = a->chain;
 	    if( DBG_IOBUF )
 		log_debug("iobuf-%d.%d: pop `%s' in underflow\n",
-                          a->no, a->subno, a->desc?a->desc:"?" );
+                          a->no, a->subno, iobuf_desc (a, desc) );
 	    xfree(a->d.buf);
 	    xfree(a->real_fname);
 	    memcpy(a, b, sizeof *a);
@@ -1625,7 +1642,6 @@ underflow(IOBUF a)
 		a->filter_ov = NULL;
 	    }
 	    a->filter = NULL;
-	    a->desc = NULL;
 	    a->filter_ov = NULL;
 	    a->filter_eof = 1;
 	    if( !len && a->chain ) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg1.git



More information about the Pkg-gnupg-commit mailing list