From: Sergiu Deitsch Date: Sat, 4 Nov 2017 15:22:21 +0000 (+0100) Subject: Merge pull request #106 from dimhotepus/master X-Git-Tag: accepted/tizen/5.0/unified/20181102.024921~21 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bac8811710c77ac3718be1c4801f43d37c1aea46;hp=-c;p=platform%2Fupstream%2Fglog.git Merge pull request #106 from dimhotepus/master Cache strlen outside of cycles (PVS-Studio) --- bac8811710c77ac3718be1c4801f43d37c1aea46 diff --combined src/logging_unittest.cc index b8a9a87,b9b8357..59e9155 --- a/src/logging_unittest.cc +++ b/src/logging_unittest.cc @@@ -272,24 -272,17 +272,24 @@@ void TestLogging(bool check_counts) LOG(ERROR) << string("foo") << ' '<< j << ' ' << setw(10) << j << " " << setw(1) << hex << j; + { + google::LogMessage outer(__FILE__, __LINE__, google::ERROR); + outer.stream() << "outer"; + + LOG(ERROR) << "inner"; + } + LogMessage("foo", LogMessage::kNoLogPrefix, GLOG_INFO).stream() << "no prefix"; if (check_counts) { CHECK_EQ(base_num_infos + 14, LogMessage::num_messages(GLOG_INFO)); CHECK_EQ(base_num_warning + 3, LogMessage::num_messages(GLOG_WARNING)); - CHECK_EQ(base_num_errors + 15, LogMessage::num_messages(GLOG_ERROR)); + CHECK_EQ(base_num_errors + 17, LogMessage::num_messages(GLOG_ERROR)); } } static void NoAllocNewHook() { - CHECK(false) << "unexpected new"; + LOG(FATAL) << "unexpected new"; } struct NewHook { @@@ -775,17 -768,18 +775,18 @@@ static void TestOneTruncate(const char CHECK_ERR(fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0600)); const char *discardstr = "DISCARDME!", *keepstr = "KEEPME!"; + const size_t discard_size = strlen(discardstr), keep_size = strlen(keepstr); // Fill the file with the requested data; first discard data, then kept data int64 written = 0; while (written < dsize) { - int bytes = min(dsize - written, strlen(discardstr)); + int bytes = min(dsize - written, discard_size); CHECK_ERR(write(fd, discardstr, bytes)); written += bytes; } written = 0; while (written < ksize) { - int bytes = min(ksize - written, strlen(keepstr)); + int bytes = min(ksize - written, keep_size); CHECK_ERR(write(fd, keepstr, bytes)); written += bytes; } @@@ -807,7 -801,7 +808,7 @@@ const char *p = buf; int64 checked = 0; while (checked < expect) { - int bytes = min(expect - checked, strlen(keepstr)); + int bytes = min(expect - checked, keep_size); CHECK(!memcmp(p, keepstr, bytes)); checked += bytes; }