aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaeMan Park <jaeman@google.com>2024-01-16 11:22:25 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2024-01-16 11:22:25 +0000
commit05b53fd2340a93ba931d1c1f5f7ca08e3d008bf5 (patch)
treebb8c80ed219109bbef3f155878e18fe1d9b00912
parent6b143f3d71b2607058045a993c5489dd08475212 (diff)
parent56364b59866771fdbf03d9098c93c4047ccd228d (diff)
downloadaidl-05b53fd2340a93ba931d1c1f5f7ca08e3d008bf5.tar.gz
Fix cert-dcl50-cpp tidy warnings am: 65634abf08 am: ccc36aa01e am: 56364b5986
Original change: https://android-review.googlesource.com/c/platform/system/tools/aidl/+/2897507 Change-Id: Iae2e3ba04d35093a3b88dd992c4fe3b733861617 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--Android.bp1
-rw-r--r--code_writer.cpp18
-rw-r--r--code_writer.h18
-rw-r--r--tests/fake_io_delegate.cpp2
4 files changed, 23 insertions, 16 deletions
diff --git a/Android.bp b/Android.bp
index c743bde1..1c506642 100644
--- a/Android.bp
+++ b/Android.bp
@@ -46,7 +46,6 @@ cc_defaults {
"-bugprone-misplaced-widening-cast",
"-bugprone-signed-char-misuse",
"-bugprone-sizeof-expression",
- "-cert-dcl50-cpp",
"-cert-err34-c",
"-cert-err52-cpp",
"-cert-str34-c",
diff --git a/code_writer.cpp b/code_writer.cpp
index 773a598f..8dd59da8 100644
--- a/code_writer.cpp
+++ b/code_writer.cpp
@@ -24,8 +24,6 @@
#include <unordered_map>
#include <vector>
-#include <android-base/stringprintf.h>
-
namespace android {
namespace aidl {
@@ -42,23 +40,17 @@ std::string CodeWriter::ApplyIndent(const std::string& str) {
return output;
}
-bool CodeWriter::Write(const char* format, ...) {
- va_list ap;
- va_start(ap, format);
- std::string formatted;
- android::base::StringAppendV(&formatted, format, ap);
- va_end(ap);
-
+bool CodeWriter::WriteString(const std::string& str) {
// extract lines. empty line is preserved.
std::vector<std::string> lines;
size_t pos = 0;
- while (pos < formatted.size()) {
- size_t line_end = formatted.find('\n', pos);
+ while (pos < str.size()) {
+ size_t line_end = str.find('\n', pos);
if (line_end != std::string::npos) {
- lines.push_back(formatted.substr(pos, (line_end - pos) + 1));
+ lines.push_back(str.substr(pos, (line_end - pos) + 1));
pos = line_end + 1;
} else {
- lines.push_back(formatted.substr(pos));
+ lines.push_back(str.substr(pos));
break;
}
}
diff --git a/code_writer.h b/code_writer.h
index 75013856..7d2a265e 100644
--- a/code_writer.h
+++ b/code_writer.h
@@ -24,6 +24,8 @@
#include <string>
#include <utility>
+#include <android-base/stringprintf.h>
+
namespace android {
namespace aidl {
@@ -41,7 +43,21 @@ class CodeWriter {
static CodeWriterPtr ForString(std::string* buf);
// Write a formatted string to this writer in the usual printf sense.
// Returns false on error.
- virtual bool Write(const char* format, ...) __attribute__((format(printf, 2, 3)));
+ template <typename... Args>
+ bool Write(const char* format, Args... args) __attribute__((format(printf, 2, 0))) {
+ std::string formatted;
+ android::base::StringAppendF(&formatted, format, args...);
+
+ return WriteString(formatted);
+ }
+
+ template <>
+ bool Write(const char* str) {
+ return WriteString(str);
+ }
+
+ virtual bool WriteString(const std::string&);
+
void Indent();
void Dedent();
virtual bool Close();
diff --git a/tests/fake_io_delegate.cpp b/tests/fake_io_delegate.cpp
index 41fa2a12..1ab1499d 100644
--- a/tests/fake_io_delegate.cpp
+++ b/tests/fake_io_delegate.cpp
@@ -36,7 +36,7 @@ namespace test {
// Claims to always write successfully, but can't close the file.
class BrokenCodeWriter : public CodeWriter {
- bool Write(const char* /* format */, ...) override { return true; }
+ bool WriteString(const std::string& /* str */) override { return true; }
bool Close() override { return false; }
~BrokenCodeWriter() override = default;
}; // class BrokenCodeWriter