www.libssh2.org | Daily snapshots | Mailing list archive | Docs | Examples | github

Archive Index This month's Index

Subject: [PATCH 1/2] libgcrypt.h: Make SHA1 and MD5 finalization use do { .. } while (0)

[PATCH 1/2] libgcrypt.h: Make SHA1 and MD5 finalization use do { .. } while (0)

From: Peter Stuge <peter_at_stuge.se>
Date: Tue, 13 Nov 2012 04:26:27 +0100

The libssh2_sha1_final() and libssh2_md5_final() macros had definitions
calling both memcpy() and gcry_md_close() separated by a comma. It's
nicer to have the definition as a single do {} while (0) statement.

---
 src/libgcrypt.h |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/libgcrypt.h b/src/libgcrypt.h
index 1f0276e..2f9864f 100644
--- a/src/libgcrypt.h
+++ b/src/libgcrypt.h
@@ -62,8 +62,10 @@
 #define libssh2_sha1_ctx gcry_md_hd_t
 #define libssh2_sha1_init(ctx) gcry_md_open (ctx,  GCRY_MD_SHA1, 0);
 #define libssh2_sha1_update(ctx, data, len) gcry_md_write (ctx, data, len)
-#define libssh2_sha1_final(ctx, out) \
-  memcpy (out, gcry_md_read (ctx, 0), SHA_DIGEST_LENGTH), gcry_md_close (ctx)
+#define libssh2_sha1_final(ctx, out) do { \
+    memcpy (out, gcry_md_read (ctx, 0), SHA_DIGEST_LENGTH); \
+    gcry_md_close (ctx); \
+  } while (0)
 #define libssh2_sha1(message, len, out) \
   gcry_md_hash_buffer (GCRY_MD_SHA1, out, message, len)
 
@@ -74,8 +76,10 @@
   (GPG_ERR_NO_ERROR == gcry_md_open (ctx,  GCRY_MD_MD5, 0))
 
 #define libssh2_md5_update(ctx, data, len) gcry_md_write (ctx, data, len)
-#define libssh2_md5_final(ctx, out) \
-  memcpy (out, gcry_md_read (ctx, 0), MD5_DIGEST_LENGTH), gcry_md_close (ctx)
+#define libssh2_md5_final(ctx, out) do { \
+    memcpy (out, gcry_md_read (ctx, 0), MD5_DIGEST_LENGTH); \
+    gcry_md_close (ctx); \
+  } while (0)
 #define libssh2_md5(message, len, out) \
   gcry_md_hash_buffer (GCRY_MD_MD5, out, message, len)
 
-- 
1.7.4.1.343.ga91df.dirty
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2012-11-13

the libssh2 team