[flang-commits] [flang] [flang] add SYSTEM runtime and lowering intrinsics support (PR #74309)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Dec 13 09:15:54 PST 2023


================
@@ -282,4 +282,40 @@ std::int32_t RTNAME(GetEnvVariable)(const Descriptor &name,
   return StatOk;
 }
 
+const char *ensureNullTerminated(
+    const char *str, size_t length, Terminator &terminator) {
+  if (length <= strlen(str)) {
+    char *newCmd{(char *)malloc(length + 1)};
+    if (newCmd == NULL) {
+      terminator.Crash("Command not null-terminated, memory allocation failed "
+                       "for null-terminated newCmd.");
+    }
+
+    strncpy(newCmd, str, length);
----------------
klausler wrote:

`std::memcpy()` instead, as the length is known.

https://github.com/llvm/llvm-project/pull/74309


More information about the flang-commits mailing list