[libc-commits] [PATCH] D111913: [libc] add stpcpy and stpncpy

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Sun Oct 17 22:13:11 PDT 2021


sivachandra added inline comments.


================
Comment at: libc/src/string/stpcpy.cpp:31
+  // break the sanitizers.
+  SANITIZER_MEMORY_INITIALIZED(result, size);
+
----------------
Not sure if this is a valid argument for `mempcpy`. As in, we might want `mempcpy` to be instrumented really.


================
Comment at: libc/src/string/stpncpy.cpp:18
+                    size_t n)) {
+  size_t i = 0;
+  size_t strEnd = 0;
----------------
Nit: Instead of initializing to 0 here, do it in the `for` statement ...


================
Comment at: libc/src/string/stpncpy.cpp:21
+  // Copy up until \0 is found.
+  for (; i < n && src[i] != '\0'; ++i) {
+    dest[i] = src[i];
----------------
... like this:

```
for (i = 0; ...)
```


================
Comment at: libc/src/string/stpncpy.cpp:24
+  }
+  strEnd = i;
+  // When n>strlen(src), n-strlen(src) \0 are appended.
----------------
Nit: This can be

```
size_t end = i;
```


================
Comment at: libc/src/string/stpncpy.cpp:26
+  // When n>strlen(src), n-strlen(src) \0 are appended.
+  for (; i < n; ++i)
+    dest[i] = '\0';
----------------
Can this `for` loop be replaced with a call to `bzero`?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D111913/new/

https://reviews.llvm.org/D111913



More information about the libc-commits mailing list