1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-19 18:15:18 -07:00

Avoid memmove() call when buffers are already the same. (#935)

This completes the work started in commit
fbe3eb265f
This commit is contained in:
Loup Vaillant 2020-03-11 19:05:57 +01:00 committed by GitHub
parent a0a8706c9d
commit 4bbc34c09c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -101,9 +101,9 @@ crypto_secretbox_open_detached(unsigned char *m, const unsigned char *c,
if (m == NULL) {
return 0;
}
if (((uintptr_t) c >= (uintptr_t) m &&
if (((uintptr_t) c > (uintptr_t) m &&
(uintptr_t) c - (uintptr_t) m < clen) ||
((uintptr_t) m >= (uintptr_t) c &&
((uintptr_t) m > (uintptr_t) c &&
(uintptr_t) m - (uintptr_t) c < clen)) { /* LCOV_EXCL_LINE */
memmove(m, c, clen);
c = m;

View File

@ -108,9 +108,9 @@ crypto_secretbox_xchacha20poly1305_open_detached(unsigned char *m,
if (m == NULL) {
return 0;
}
if (((uintptr_t) c >= (uintptr_t) m &&
if (((uintptr_t) c > (uintptr_t) m &&
(uintptr_t) c - (uintptr_t) m < clen) ||
((uintptr_t) m >= (uintptr_t) c &&
((uintptr_t) m > (uintptr_t) c &&
(uintptr_t) m - (uintptr_t) c < clen)) { /* LCOV_EXCL_LINE */
memmove(m, c, clen);
c = m;