[Cryptech-Commits] [sw/pkcs11] 01/03: Clean up a few gratuitous obscurities.
git at cryptech.is
git at cryptech.is
Fri May 19 04:46:05 UTC 2017
This is an automated email from the git hooks/post-receive script.
sra at hactrn.net pushed a commit to branch master
in repository sw/pkcs11.
commit fb454260b582d418671e8a1ff45092e27709cd6d
Author: Rob Austein <sra at hactrn.net>
AuthorDate: Thu May 18 16:44:02 2017 -0400
Clean up a few gratuitous obscurities.
---
pkcs11.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/pkcs11.c b/pkcs11.c
index 148a1a6..fbc0845 100644
--- a/pkcs11.c
+++ b/pkcs11.c
@@ -593,14 +593,19 @@ static CK_RV posix_mutex_unlock(CK_VOID_PTR pMutex)
* Bit mask twiddling utilities.
*/
+static inline CK_ULONG mask_pos(const CK_ULONG mask)
+{
+ return mask & ~(mask - 1); /* Finds least significant bit set in mask */
+}
+
static inline CK_ULONG mask_ldb(const CK_ULONG mask, const CK_ULONG value)
{
- return (value & mask) / (mask & ~(mask - 1));
+ return (value & mask) / mask_pos(mask);
}
static inline CK_ULONG mask_dpb(const CK_ULONG mask, const CK_ULONG value)
{
- return (value * (mask & ~(mask - 1))) & mask;
+ return (value * mask_pos(mask)) & mask;
}
/*
@@ -677,9 +682,6 @@ static inline unsigned handle_index(const CK_ULONG handle)
return mask_ldb(HANDLE_MASK_INDEX, handle);
}
-// Backwards compatability, probably phase this out
-#define is_token_handle(_handle_) (handle_flavor(_handle_) == handle_flavor_token_object)
-
/*
@@ -1633,15 +1635,15 @@ static int p11_session_consistent_login(void)
static int psnprintf(void *buffer_, size_t size, const char *format, ...)
{
char buffer[size + 1];
- size_t i, n;
+ size_t n;
va_list ap;
va_start(ap, format);
- i = n = vsnprintf(buffer, sizeof(buffer), format, ap);
+ n = vsnprintf(buffer, sizeof(buffer), format, ap);
va_end(ap);
- while (i < size)
- buffer[i++] = ' ';
+ for (size_t i = n; i < size; i++)
+ buffer[i] = ' ';
memcpy(buffer_, buffer, size);
More information about the Commits
mailing list