diff options
author | JaeMan Park <jaeman@google.com> | 2024-01-16 10:18:24 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2024-01-16 10:18:24 +0000 |
commit | ccc36aa01e5e830b70e17bbeb0e6532e1983c583 (patch) | |
tree | bb8c80ed219109bbef3f155878e18fe1d9b00912 | |
parent | a133e8135c656d5b018f4d6cb10ea87c7dded3b3 (diff) | |
parent | 65634abf082aafaaef8133003f2161a64fc78b0f (diff) | |
download | aidl-ccc36aa01e5e830b70e17bbeb0e6532e1983c583.tar.gz |
Fix cert-dcl50-cpp tidy warnings am: 65634abf08
Original change: https://android-review.googlesource.com/c/platform/system/tools/aidl/+/2897507
Change-Id: I29c0b70bb94b6bd904f77f11e67e181d976801d9
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | Android.bp | 1 | ||||
-rw-r--r-- | code_writer.cpp | 18 | ||||
-rw-r--r-- | code_writer.h | 18 | ||||
-rw-r--r-- | tests/fake_io_delegate.cpp | 2 |
4 files changed, 23 insertions, 16 deletions
@@ -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 |