diff options
author | Andrei Homescu <ahomescu@google.com> | 2022-12-02 23:48:31 +0000 |
---|---|---|
committer | Ayrton Munoz <ayrton@google.com> | 2022-12-04 23:58:33 +0000 |
commit | 77a94784054ca19b2ca67ded19d5b69ce7cc3b7f (patch) | |
tree | 3e46f5d1a609c4f43f05fadeb1b204fa576f56a1 /lib | |
parent | 96f1f117f76cda66a9a0e2b2124cdfeb7295d9a3 (diff) | |
download | common-77a94784054ca19b2ca67ded19d5b69ce7cc3b7f.tar.gz |
lib/libc: Replace long => uintptr_t in mem{cpy,move}
The lk implementations of mem{cpy,move} internally
cast some pointers to long, which triggers UBSan.
This replaces the target type with uintptr_t which
fixes the issue (and it matches the original char*
pointer types better).
Bug: 231151995
Change-Id: Ia915baae1f167204aaffe4998d4f75a9e516677a
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/string/memcpy.c | 6 | ||||
-rw-r--r-- | lib/libc/string/memmove.c | 15 |
2 files changed, 11 insertions, 10 deletions
diff --git a/lib/libc/string/memcpy.c b/lib/libc/string/memcpy.c index d618c156..29e6d278 100644 --- a/lib/libc/string/memcpy.c +++ b/lib/libc/string/memcpy.c @@ -44,12 +44,12 @@ void *memcpy(void *dest, const void *src, size_t count) if (count == 0 || dest == src) return dest; - if (((long)d | (long)s) & lmask) { + if (((uintptr_t)d | (uintptr_t)s) & lmask) { // src and/or dest do not align on word boundary - if ((((long)d ^ (long)s) & lmask) || (count < lsize)) + if ((((uintptr_t)d ^ (uintptr_t)s) & lmask) || (count < lsize)) len = count; // copy the rest of the buffer with the byte mover else - len = lsize - ((long)d & lmask); // move the ptrs up to a word boundary + len = lsize - ((uintptr_t)d & lmask); // move the ptrs up to a word boundary count -= len; for (; len > 0; len--) diff --git a/lib/libc/string/memmove.c b/lib/libc/string/memmove.c index c7da3504..38d1e2ff 100644 --- a/lib/libc/string/memmove.c +++ b/lib/libc/string/memmove.c @@ -24,6 +24,7 @@ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include <stdint.h> #include <string.h> #include <sys/types.h> @@ -44,13 +45,13 @@ memmove(void *dest, void const *src, size_t count) if (count == 0 || dest == src) return dest; - if ((long)d < (long)s) { - if (((long)d | (long)s) & lmask) { + if ((uintptr_t)d < (uintptr_t)s) { + if (((uintptr_t)d | (uintptr_t)s) & lmask) { // src and/or dest do not align on word boundary - if ((((long)d ^ (long)s) & lmask) || (count < lsize)) + if ((((uintptr_t)d ^ (uintptr_t)s) & lmask) || (count < lsize)) len = count; // copy the rest of the buffer with the byte mover else - len = lsize - ((long)d & lmask); // move the ptrs up to a word boundary + len = lsize - ((uintptr_t)d & lmask); // move the ptrs up to a word boundary count -= len; for (; len > 0; len--) @@ -66,12 +67,12 @@ memmove(void *dest, void const *src, size_t count) } else { d += count; s += count; - if (((long)d | (long)s) & lmask) { + if (((uintptr_t)d | (uintptr_t)s) & lmask) { // src and/or dest do not align on word boundary - if ((((long)d ^ (long)s) & lmask) || (count <= lsize)) + if ((((uintptr_t)d ^ (uintptr_t)s) & lmask) || (count <= lsize)) len = count; else - len = ((long)d & lmask); + len = ((uintptr_t)d & lmask); count -= len; for (; len > 0; len--) |