[compiler-rt] [DFSan] Fix sscanf wrapper handling %*d (the star skips capturing). (PR #67392)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Sep 25 22:30:57 PDT 2023
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 38dd67c8b3dbce4311e32a68d1100bd9f850c43e 33d1b30e07eb7f718cddcd898cefc934613248bd -- compiler-rt/lib/dfsan/dfsan_custom.cpp compiler-rt/test/dfsan/custom.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp
index 6cad29f0c76c..38371d353368 100644
--- a/compiler-rt/lib/dfsan/dfsan_custom.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp
@@ -2623,14 +2623,14 @@ static int scan_buffer(char *str, size_t size, const char *fmt,
}
// get the label associated with the string at the corresponding
// place
- dfsan_label l = dfsan_read_label(formatter.str_cur(),
- formatter.num_written_bytes(read_count));
+ dfsan_label l = dfsan_read_label(
+ formatter.str_cur(), formatter.num_written_bytes(read_count));
dfsan_set_label(l, dst_ptr, write_size);
if (str_origin != nullptr) {
- dfsan_set_label(l, dst_ptr, write_size);
- size_t scan_count = formatter.num_written_bytes(read_count);
- size_t size = scan_count > write_size ? write_size : scan_count;
- dfsan_mem_origin_transfer(dst_ptr, formatter.str_cur(), size);
+ dfsan_set_label(l, dst_ptr, write_size);
+ size_t scan_count = formatter.num_written_bytes(read_count);
+ size_t size = scan_count > write_size ? write_size : scan_count;
+ dfsan_mem_origin_transfer(dst_ptr, formatter.str_cur(), size);
}
}
end_fmt = true;
@@ -2649,26 +2649,26 @@ static int scan_buffer(char *str, size_t size, const char *fmt,
read_count = formatter.scan();
} else {
if (*(formatter.fmt_cur - 1) == 'L') {
- dst_ptr = va_arg(ap, long double *);
- read_count = formatter.scan((long double *)dst_ptr);
- write_size = sizeof(long double);
+ dst_ptr = va_arg(ap, long double *);
+ read_count = formatter.scan((long double *)dst_ptr);
+ write_size = sizeof(long double);
} else if (*(formatter.fmt_cur - 1) == 'l') {
- dst_ptr = va_arg(ap, double *);
- read_count = formatter.scan((double *)dst_ptr);
- write_size = sizeof(double);
+ dst_ptr = va_arg(ap, double *);
+ read_count = formatter.scan((double *)dst_ptr);
+ write_size = sizeof(double);
} else {
- dst_ptr = va_arg(ap, float *);
- read_count = formatter.scan((float *)dst_ptr);
- write_size = sizeof(float);
+ dst_ptr = va_arg(ap, float *);
+ read_count = formatter.scan((float *)dst_ptr);
+ write_size = sizeof(float);
}
- dfsan_label l = dfsan_read_label(formatter.str_cur(),
- formatter.num_written_bytes(read_count));
+ dfsan_label l = dfsan_read_label(
+ formatter.str_cur(), formatter.num_written_bytes(read_count));
dfsan_set_label(l, dst_ptr, write_size);
if (str_origin != nullptr) {
- dfsan_set_label(l, dst_ptr, write_size);
- size_t scan_count = formatter.num_written_bytes(read_count);
- size_t size = scan_count > write_size ? write_size : scan_count;
- dfsan_mem_origin_transfer(dst_ptr, formatter.str_cur(), size);
+ dfsan_set_label(l, dst_ptr, write_size);
+ size_t scan_count = formatter.num_written_bytes(read_count);
+ size_t size = scan_count > write_size ? write_size : scan_count;
+ dfsan_mem_origin_transfer(dst_ptr, formatter.str_cur(), size);
}
}
end_fmt = true;
@@ -2681,13 +2681,13 @@ static int scan_buffer(char *str, size_t size, const char *fmt,
dst_ptr = va_arg(ap, char *);
read_count = formatter.scan((char *)dst_ptr);
write_size = sizeof(char);
- dfsan_label l = dfsan_read_label(formatter.str_cur(),
- formatter.num_written_bytes(read_count));
+ dfsan_label l = dfsan_read_label(
+ formatter.str_cur(), formatter.num_written_bytes(read_count));
dfsan_set_label(l, dst_ptr, write_size);
if (str_origin != nullptr) {
- size_t scan_count = formatter.num_written_bytes(read_count);
- size_t size = scan_count > write_size ? write_size : scan_count;
- dfsan_mem_origin_transfer(dst_ptr, formatter.str_cur(), size);
+ size_t scan_count = formatter.num_written_bytes(read_count);
+ size_t size = scan_count > write_size ? write_size : scan_count;
+ dfsan_mem_origin_transfer(dst_ptr, formatter.str_cur(), size);
}
}
end_fmt = true;
@@ -2700,13 +2700,13 @@ static int scan_buffer(char *str, size_t size, const char *fmt,
dst_ptr = va_arg(ap, char *);
read_count = formatter.scan((char *)dst_ptr);
if (1 == read_count) {
- // special case: we have parsed a single string and we need to
- // update read_count with the string size
- read_count = strlen((char *)dst_ptr);
+ // special case: we have parsed a single string and we need to
+ // update read_count with the string size
+ read_count = strlen((char *)dst_ptr);
}
if (str_origin)
- dfsan_mem_origin_transfer(dst_ptr, formatter.str_cur(),
- formatter.num_written_bytes(read_count));
+ dfsan_mem_origin_transfer(dst_ptr, formatter.str_cur(),
+ formatter.num_written_bytes(read_count));
va_labels++;
dfsan_mem_shadow_transfer(dst_ptr, formatter.str_cur(),
formatter.num_written_bytes(read_count));
@@ -2725,14 +2725,14 @@ static int scan_buffer(char *str, size_t size, const char *fmt,
// since we need to call sizeof
write_size = sizeof(int);
- dfsan_label l = dfsan_read_label(formatter.str_cur(),
- formatter.num_written_bytes(read_count));
+ dfsan_label l = dfsan_read_label(
+ formatter.str_cur(), formatter.num_written_bytes(read_count));
dfsan_set_label(l, dst_ptr, write_size);
if (str_origin != nullptr) {
- dfsan_set_label(l, dst_ptr, write_size);
- size_t scan_count = formatter.num_written_bytes(read_count);
- size_t size = scan_count > write_size ? write_size : scan_count;
- dfsan_mem_origin_transfer(dst_ptr, formatter.str_cur(), size);
+ dfsan_set_label(l, dst_ptr, write_size);
+ size_t scan_count = formatter.num_written_bytes(read_count);
+ size_t size = scan_count > write_size ? write_size : scan_count;
+ dfsan_mem_origin_transfer(dst_ptr, formatter.str_cur(), size);
}
}
end_fmt = true;
@@ -2745,7 +2745,7 @@ static int scan_buffer(char *str, size_t size, const char *fmt,
*va_labels++ = 0;
dfsan_set_label(0, ptr, sizeof(*ptr));
if (str_origin != nullptr)
- *str_origin++ = 0;
+ *str_origin++ = 0;
}
end_fmt = true;
break;
diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp
index c8836707fc91..56e66fd5069a 100644
--- a/compiler-rt/test/dfsan/custom.cpp
+++ b/compiler-rt/test/dfsan/custom.cpp
@@ -2166,13 +2166,13 @@ void test_sscanf() {
dfsan_set_label(k_label, (void *)(s + 1), 2); // buf[7]-b[9]
dfsan_origin s_o = dfsan_get_origin((long)(s[1]));
assert(s[10] == '2');
- dfsan_set_label(i_label, (void *)(s + 10), 4); // 2014
+ dfsan_set_label(i_label, (void *)(s + 10), 4); // 2014
dfsan_origin y_o = dfsan_get_origin((long)s[10]); // buf[16]
assert(s[17] == '3');
- dfsan_set_label(j_label, (void *)(s + 17), 2); // 31
+ dfsan_set_label(j_label, (void *)(s + 17), 2); // 31
dfsan_origin d_o = dfsan_get_origin((long)s[17]); // buf[23]
assert(s[20] == '1');
- dfsan_set_label(m_label, (void *)(s + 20), 5); // 12345
+ dfsan_set_label(m_label, (void *)(s + 20), 5); // 12345
dfsan_origin f_o = dfsan_get_origin((long)s[20]); //buf[26]
#ifndef ORIGIN_TRACKING
``````````
</details>
https://github.com/llvm/llvm-project/pull/67392
More information about the llvm-commits
mailing list