1 //===-- Implementation of strcpy ------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "src/string/strcpy.h"
10 #include "src/string/memcpy.h"
11 #include "src/string/string_utils.h"
12 
13 #include "src/__support/common.h"
14 #include "src/__support/sanitizer.h"
15 
16 namespace __llvm_libc {
17 
18 LLVM_LIBC_FUNCTION(char *, strcpy,
19                    (char *__restrict dest, const char *__restrict src)) {
20   size_t size = internal::string_length(src) + 1;
21   char *result = reinterpret_cast<char *>(__llvm_libc::memcpy(dest, src, size));
22 
23   // In many libc uses, we do not want memcpy to be instrumented. Hence,
24   // we mark the destination as initialized.
25   //
26   // We do not want memcpy to be instrumented because compilers can potentially
27   // generate calls to memcpy. If the sanitizer business logic ends up with a
28   // compiler generated call to memcpy which is instrumented, then it will
29   // break the sanitizers.
30   SANITIZER_MEMORY_INITIALIZED(result, size);
31 
32   return result;
33 }
34 
35 } // namespace __llvm_libc
36