Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e8a57c14 authored by Steven Moreland's avatar Steven Moreland
Browse files

binder_parcel_fuzzer: remove expensive logging

- logging disabled by default
- avoid std::stringstream construction entirely

Bug: 142473153
Test: binder_parcel_fuzzer w/, w/o fuzzing option enabled
Change-Id: Ie9e3109d4b9eddf7150ecaf4d5d1b8ba46662af4
parent 2884dd8b
Loading
Loading
Loading
Loading
+20 −13
Original line number Diff line number Diff line
@@ -23,27 +23,34 @@
#error "Must define FUZZ_LOG_TAG"
#endif

#define ENABLE_LOG_FUZZ 1
#define FUZZ_LOG() FuzzLog(FUZZ_LOG_TAG, ENABLE_LOG_FUZZ).log()
// for local debugging
#define ENABLE_LOG_FUZZ 0

#define FUZZ_LOG() FuzzLog(FUZZ_LOG_TAG).log()

#if ENABLE_LOG_FUZZ == 1
class FuzzLog {
public:
    FuzzLog(const std::string& tag, bool log) : mTag(tag), mLog(log) {}
    ~FuzzLog() {
        if (mLog) {
            std::cout << mTag << ": " << mOs.str() << std::endl;
        }
    }
    FuzzLog(const char* tag) : mTag(tag) {}
    ~FuzzLog() { std::cout << mTag << ": " << mOs.str() << std::endl; }

    std::stringstream& log() {
        return mOs;
    }
    std::stringstream& log() { return mOs; }

private:
    std::string mTag;
    bool mLog;
    const char* mTag = nullptr;
    std::stringstream mOs;
};
#else
class FuzzLog {
public:
    FuzzLog(const char* /*tag*/) {}
    template <typename T>
    FuzzLog& operator<<(const T& /*t*/) {
        return *this;
    }
    FuzzLog& log() { return *this; }
};
#endif

std::string hexString(const void* bytes, size_t len);
std::string hexString(const std::vector<uint8_t>& bytes);