[Openmp-commits] [PATCH] D91309: [OpenMP] Fixed a bug when displaying affinity

Shilei Tian via Phabricator via Openmp-commits openmp-commits at lists.llvm.org
Wed Nov 11 17:04:51 PST 2020

tianshilei1992 created this revision.
Herald added subscribers: openmp-commits, guansong, yaxunl.
Herald added a project: OpenMP.
tianshilei1992 requested review of this revision.
Herald added a reviewer: jdoerfert.
Herald added a subscriber: sstefan1.

Currently the affinity format string has initial value. When users set
the format via OMP_AFFINITY_FORMAT, it will overwrite the format string. However,
when copying the format, the tailing null is missing. As a result, if the user
format string is shorter than default value, the remaining part in the default
value still makes effort. This bug is not exposed because the test case doesn't
check the end of a string. It only checks whether given output "contains" the
check string.

  rG LLVM Github Monorepo



Index: openmp/runtime/test/affinity/format/simple_env.c
--- openmp/runtime/test/affinity/format/simple_env.c
+++ openmp/runtime/test/affinity/format/simple_env.c
@@ -13,4 +13,4 @@
   return 0;
-// CHECK-8: num_threads=8 TESTER-ENV: tl:1 tn:[0-7] nt:8
+// CHECK-8: num_threads=8 TESTER-ENV: tl:1 tn:[0-7] nt:8$
Index: openmp/runtime/src/kmp_safe_c_api.h
--- openmp/runtime/src/kmp_safe_c_api.h
+++ openmp/runtime/src/kmp_safe_c_api.h
@@ -64,11 +64,9 @@
                                           char const *src, size_t src_size) {
   if (src_size >= buf_size) {
     src_size = buf_size - 1;
-    KMP_STRNCPY_S(buffer, buf_size, src, src_size);
-    buffer[buf_size - 1] = '\0';
-  } else {
-    KMP_STRNCPY_S(buffer, buf_size, src, src_size);
+  KMP_STRNCPY_S(buffer, buf_size, src, src_size);
+  buffer[src_size] = '\0';
 #endif // KMP_SAFE_C_API_H

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91309.304687.patch
Type: text/x-patch
Size: 1002 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20201112/5ea774d7/attachment-0001.bin>

More information about the Openmp-commits mailing list