aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Chatelet <gchatelet@google.com>2023-12-04 10:57:35 +0100
committerGitHub <noreply@github.com>2023-12-04 10:57:35 +0100
commit8628ca29aa4714f99e865c99b9d510ad14897fdc (patch)
treed13281d776c1668aa0ebc30d418b3302e8d0eee0
parent077fe9773632b955ad114eeeb4153c734a9f5172 (diff)
downloadllvm-8628ca29aa4714f99e865c99b9d510ad14897fdc.zip
llvm-8628ca29aa4714f99e865c99b9d510ad14897fdc.tar.gz
llvm-8628ca29aa4714f99e865c99b9d510ad14897fdc.tar.bz2
[libc] Fix UB in memory utils (#74295)
The [standard](https://eel.is/c++draft/expr.add#4.3) forbids forming pointers to invalid objects even if the pointer is never read from or written to. This patch makes sure that we don't do pointer arithmetic on invalid pointers. Co-authored-by: Vitaly Buka <vitalybuka@google.com>
-rw-r--r--libc/src/string/memory_utils/utils.h6
1 files changed, 3 insertions, 3 deletions
diff --git a/libc/src/string/memory_utils/utils.h b/libc/src/string/memory_utils/utils.h
index f70880e..9c29318 100644
--- a/libc/src/string/memory_utils/utils.h
+++ b/libc/src/string/memory_utils/utils.h
@@ -341,9 +341,9 @@ void align_p1_to_next_boundary(T1 *__restrict &p1, T2 *__restrict &p2,
}
// Same as align_p1_to_next_boundary above but with a single pointer instead.
-template <size_t SIZE, typename T1>
-LIBC_INLINE void align_to_next_boundary(T1 *&p1, size_t &count) {
- CPtr dummy;
+template <size_t SIZE, typename T>
+LIBC_INLINE void align_to_next_boundary(T *&p1, size_t &count) {
+ const T *dummy = p1;
align_p1_to_next_boundary<SIZE>(p1, dummy, count);
}