Merge "liblog: don't return 0xFFFFFFFF as an invalid log id."

This commit is contained in:
Josh Gao 2019-03-27 00:24:47 +00:00 committed by Gerrit Code Review
commit 49a8eecc5f
2 changed files with 15 additions and 2 deletions

View File

@ -50,8 +50,9 @@ log_id_t android_name_to_log_id(const char* logName) {
unsigned int ret;
if (!logName) {
return static_cast<log_id_t>(0xFFFFFFFF);
return static_cast<log_id_t>(LOG_ID_MAX);
}
b = strrchr(logName, '/');
if (!b) {
b = logName;
@ -65,5 +66,6 @@ log_id_t android_name_to_log_id(const char* logName) {
return static_cast<log_id_t>(ret);
}
}
return static_cast<log_id_t>(0xFFFFFFFF); /* should never happen */
return static_cast<log_id_t>(LOG_ID_MAX);
}

View File

@ -33,6 +33,7 @@
#include <android-base/file.h>
#include <android-base/macros.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <gtest/gtest.h>
#include <log/event_tag_map.h>
#include <log/log.h>
@ -1747,3 +1748,13 @@ TEST(logcat, help) {
EXPECT_EQ(logcatHelpTextSize * 2, logcatLastHelpTextSize);
#endif
}
TEST(logcat, invalid_buffer) {
FILE* fp = popen("logcat -b foo 2>&1", "r");
ASSERT_NE(nullptr, fp);
std::string output;
ASSERT_TRUE(android::base::ReadFdToString(fileno(fp), &output));
pclose(fp);
ASSERT_TRUE(android::base::StartsWith(output, "unknown buffer foo\n"));
}