From 6af92365ea7ae08b33fcf08e6f7b6deeebd0cb79 Mon Sep 17 00:00:00 2001 From: Michael Stefaniuc Date: Tue, 5 Feb 2013 13:22:27 +0100 Subject: [PATCH] crypt32: Use assignment instead of memcpy to copy structs. --- dlls/crypt32/cert.c | 15 +++++---------- dlls/crypt32/message.c | 3 +-- dlls/crypt32/serialize.c | 6 +++--- dlls/crypt32/tests/main.c | 4 ++-- 4 files changed, 11 insertions(+), 17 deletions(-) diff --git a/dlls/crypt32/cert.c b/dlls/crypt32/cert.c index 478fff3857a..c137746b828 100644 --- a/dlls/crypt32/cert.c +++ b/dlls/crypt32/cert.c @@ -842,7 +842,7 @@ static BOOL container_matches_cert(PCCERT_CONTEXT pCert, LPCSTR container, * keyProvInfo->pwszContainerName to be NULL or a heap-allocated container * name. */ - memcpy(©, keyProvInfo, sizeof(copy)); + copy = *keyProvInfo; copy.pwszContainerName = containerW; matches = key_prov_info_matches_cert(pCert, ©); if (matches) @@ -2216,9 +2216,7 @@ BOOL WINAPI CryptSignAndEncodeCertificate(HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hCrypt info.ToBeSigned.cbData = encodedSize; info.ToBeSigned.pbData = encoded; - memcpy(&info.SignatureAlgorithm, - pSignatureAlgorithm, - sizeof(info.SignatureAlgorithm)); + info.SignatureAlgorithm = *pSignatureAlgorithm; info.Signature.cbData = hashSize; info.Signature.pbData = hash; info.Signature.cUnusedBits = 0; @@ -2986,8 +2984,7 @@ static PCCERT_CONTEXT CRYPT_CreateSignedCert(const CRYPT_DER_BLOB *blob, signedInfo.ToBeSigned.cbData = blob->cbData; signedInfo.ToBeSigned.pbData = blob->pbData; - memcpy(&signedInfo.SignatureAlgorithm, sigAlgo, - sizeof(signedInfo.SignatureAlgorithm)); + signedInfo.SignatureAlgorithm = *sigAlgo; signedInfo.Signature.cbData = sigSize; signedInfo.Signature.pbData = sig; signedInfo.Signature.cUnusedBits = 0; @@ -3038,8 +3035,7 @@ static void CRYPT_MakeCertInfo(PCERT_INFO info, const CRYPT_DATA_BLOB *pSerialNu info->SerialNumber.cbData = pSerialNumber->cbData; info->SerialNumber.pbData = pSerialNumber->pbData; if (pSignatureAlgorithm) - memcpy(&info->SignatureAlgorithm, pSignatureAlgorithm, - sizeof(info->SignatureAlgorithm)); + info->SignatureAlgorithm = *pSignatureAlgorithm; else { info->SignatureAlgorithm.pszObjId = oid; @@ -3066,8 +3062,7 @@ static void CRYPT_MakeCertInfo(PCERT_INFO info, const CRYPT_DATA_BLOB *pSerialNu } info->Subject.cbData = pSubjectIssuerBlob->cbData; info->Subject.pbData = pSubjectIssuerBlob->pbData; - memcpy(&info->SubjectPublicKeyInfo, pubKey, - sizeof(info->SubjectPublicKeyInfo)); + info->SubjectPublicKeyInfo = *pubKey; if (pExtensions) { info->cExtension = pExtensions->cExtension; diff --git a/dlls/crypt32/message.c b/dlls/crypt32/message.c index 7e163ded53d..5b77c87bc48 100644 --- a/dlls/crypt32/message.c +++ b/dlls/crypt32/message.c @@ -285,8 +285,7 @@ BOOL WINAPI CryptHashMessage(PCRYPT_HASH_MESSAGE_PARA pHashPara, memset(&info, 0, sizeof(info)); info.cbSize = sizeof(info); info.hCryptProv = pHashPara->hCryptProv; - memcpy(&info.HashAlgorithm, &pHashPara->HashAlgorithm, - sizeof(info.HashAlgorithm)); + info.HashAlgorithm = pHashPara->HashAlgorithm; info.pvHashAuxInfo = pHashPara->pvHashAuxInfo; msg = CryptMsgOpenToEncode(pHashPara->dwMsgEncodingType, flags, CMSG_HASHED, &info, NULL, NULL); diff --git a/dlls/crypt32/serialize.c b/dlls/crypt32/serialize.c index 5b6b7940862..7ca881c4033 100644 --- a/dlls/crypt32/serialize.c +++ b/dlls/crypt32/serialize.c @@ -652,21 +652,21 @@ static BOOL CRYPT_WriteSerializedStoreToStream(HCERTSTORE store, ret = output(handle, fileHeader, sizeof(fileHeader)); if (ret) { - memcpy(&interface, pCertInterface, sizeof(interface)); + interface = *pCertInterface; interface.serialize = (SerializeElementFunc)CRYPT_SerializeCertNoHash; ret = CRYPT_SerializeContextsToStream(output, handle, &interface, store); } if (ret) { - memcpy(&interface, pCRLInterface, sizeof(interface)); + interface = *pCRLInterface; interface.serialize = (SerializeElementFunc)CRYPT_SerializeCRLNoHash; ret = CRYPT_SerializeContextsToStream(output, handle, &interface, store); } if (ret) { - memcpy(&interface, pCTLInterface, sizeof(interface)); + interface = *pCTLInterface; interface.serialize = (SerializeElementFunc)CRYPT_SerializeCTLNoHash; ret = CRYPT_SerializeContextsToStream(output, handle, &interface, store); diff --git a/dlls/crypt32/tests/main.c b/dlls/crypt32/tests/main.c index 8ceec7b8911..a0019b58699 100644 --- a/dlls/crypt32/tests/main.c +++ b/dlls/crypt32/tests/main.c @@ -181,12 +181,12 @@ static void test_verifyTimeValidity(void) /* Check with 0 NotBefore and NotAfter */ ret = CertVerifyTimeValidity(&fileTime, &info); ok(ret == 1, "Expected 1, got %d\n", ret); - memcpy(&info.NotAfter, &fileTime, sizeof(info.NotAfter)); + info.NotAfter = fileTime; /* Check with NotAfter equal to comparison time */ ret = CertVerifyTimeValidity(&fileTime, &info); ok(ret == 0, "Expected 0, got %d\n", ret); /* Check with NotBefore after comparison time */ - memcpy(&info.NotBefore, &fileTime, sizeof(info.NotBefore)); + info.NotBefore = fileTime; info.NotBefore.dwLowDateTime += 5000; ret = CertVerifyTimeValidity(&fileTime, &info); ok(ret == -1, "Expected -1, got %d\n", ret);