diff --git a/pkcs11/rpc-layer/gkm-rpc-util.c b/pkcs11/rpc-layer/gkm-rpc-util.c
index 340baf7..e7d5a61 100644
--- a/pkcs11/rpc-layer/gkm-rpc-util.c
+++ b/pkcs11/rpc-layer/gkm-rpc-util.c
@@ -81,9 +81,10 @@ gkm_rpc_mechanism_list_purge (CK_MECHANISM_TYPE_PTR mechs, CK_ULONG* n_mechs)
 	for (i = 0; i < (int)(*n_mechs); ++i) {
 		if (!gkm_rpc_mechanism_has_no_parameters (mechs[i]) &&
 		    !gkm_rpc_mechanism_has_sane_parameters (mechs[i])) {
-
-			/* Remove the mechanism from the list */
-			memmove (&mechs[i], &mechs[i + 1], (*n_mechs - i) * sizeof (CK_MECHANISM_TYPE));
+			if (*n_mechs - i - 1 > 0) {
+				/* Remove the mechanism from the list */
+				memmove (&mechs[i], &mechs[i + 1], (*n_mechs - i - 1) * sizeof (CK_MECHANISM_TYPE));
+			}
 
 			--(*n_mechs);
 			--i;
