diff options
-rw-r--r-- | pkcs11.c | 20 |
1 files changed, 11 insertions, 9 deletions
@@ -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); |