Reland "Change SimpleStringBuilder::Append to not use strcpyn and SIZE_UNKNOWN"

This is a reland of e779847fb6499ac2dc4757de8c625ac377e9d0d4

Original change's description:
> Change SimpleStringBuilder::Append to not use strcpyn and SIZE_UNKNOWN
>
> Also add explicit includes of rtc_base/string_utils.h in files depending on it.
>
> Bug: webrtc:6424
> Change-Id: Id6b53937ab2d185d092a5d8863018fd5f1a88e27
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/135744
> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
> Commit-Queue: Niels Moller <nisse@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#27903}

Tbr: kwiberg@webrtc.org
Bug: webrtc:6424
Change-Id: Ic08d5d7fbc25ff89e4182d7c9cb3b0e8e356339a
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/135946
Reviewed-by: Niels Moller <nisse@webrtc.org>
Commit-Queue: Niels Moller <nisse@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27957}
This commit is contained in:
Niels Möller
2019-05-10 12:29:13 +02:00
committed by Commit Bot
parent baf9c62bc7
commit 198cf00532
9 changed files with 16 additions and 6 deletions

View File

@ -36,6 +36,7 @@ enum PreservedErrno {
#include "rtc_base/helpers.h"
#include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/string_utils.h"
#include "rtc_base/thread_checker.h"
#include "rtc_base/trace_event.h"
#include "usrsctplib/usrsctp.h"

View File

@ -26,6 +26,7 @@
#include "modules/audio_device/audio_device_name.h"
#include "modules/audio_device/include/audio_device_defines.h"
#include "rtc_base/logging.h"
#include "rtc_base/string_utils.h"
#pragma comment(lib, "Avrt.lib")

View File

@ -29,6 +29,7 @@
#include "rtc_base/network.h"
#include "rtc_base/numerics/safe_minmax.h"
#include "rtc_base/string_encode.h"
#include "rtc_base/string_utils.h"
#include "rtc_base/third_party/base64/base64.h"
#include "system_wrappers/include/field_trial.h"

View File

@ -45,6 +45,7 @@
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/message_digest.h"
#include "rtc_base/string_utils.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/third_party/base64/base64.h"

View File

@ -30,6 +30,7 @@
#include "rtc_base/logging.h"
#include "rtc_base/message_digest.h"
#include "rtc_base/socket_address.h"
#include "rtc_base/string_utils.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/third_party/base64/base64.h" // for Base64
#include "rtc_base/zero_memory.h" // for ExplicitZeroMemory

View File

@ -26,7 +26,7 @@ SimpleStringBuilder::SimpleStringBuilder(rtc::ArrayView<char> buffer)
}
SimpleStringBuilder& SimpleStringBuilder::operator<<(const char* str) {
return Append(str);
return Append(str, strlen(str));
}
SimpleStringBuilder& SimpleStringBuilder::operator<<(char ch) {
@ -107,11 +107,12 @@ SimpleStringBuilder& SimpleStringBuilder::AppendFormat(const char* fmt, ...) {
SimpleStringBuilder& SimpleStringBuilder::Append(const char* str,
size_t length) {
const size_t chars_added =
rtc::strcpyn(&buffer_[size_], buffer_.size() - size_, str, length);
size_ += chars_added;
RTC_DCHECK_EQ(chars_added, length == SIZE_UNKNOWN ? std::strlen(str) : length)
RTC_DCHECK_LT(size_ + length, buffer_.size())
<< "Buffer size was insufficient";
const size_t chars_added = rtc::SafeMin(length, buffer_.size() - size_ - 1);
memcpy(&buffer_[size_], str, chars_added);
size_ += chars_added;
buffer_[size_] = '\0';
RTC_DCHECK(IsConsistent());
return *this;
}

View File

@ -18,6 +18,8 @@
#include "absl/strings/string_view.h"
#include "api/array_view.h"
#include "rtc_base/string_encode.h"
// TODO(nisse): Delete, as as soon as downstream applications are updated to not
// rely in this indirect include.
#include "rtc_base/string_utils.h"
namespace rtc {
@ -64,7 +66,7 @@ class SimpleStringBuilder {
// An alternate way from operator<<() to append a string. This variant is
// slightly more efficient when the length of the string to append, is known.
SimpleStringBuilder& Append(const char* str, size_t length = SIZE_UNKNOWN);
SimpleStringBuilder& Append(const char* str, size_t length);
private:
bool IsConsistent() const {

View File

@ -19,6 +19,7 @@
#include "rtc_base/event.h"
#include "rtc_base/logging.h"
#include "rtc_base/platform_thread.h"
#include "rtc_base/string_utils.h"
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/system/inline.h"
#include "system_wrappers/include/sleep.h"

View File

@ -10,6 +10,7 @@
#ifndef TEST_LOGGING_LOG_WRITER_H_
#define TEST_LOGGING_LOG_WRITER_H_
#include <stdarg.h>
#include <memory>
#include <string>
#include <utility>