Remove usage of sprintf in modules

sprintf is marked as deprecated with Xcode 14.

Bug: chromium:1331345
Change-Id: I834f392bee96e6b6725d5aee469a243dbc6e272e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/265521
Reviewed-by: Henrik Andreassson <henrika@webrtc.org>
Reviewed-by: Henrik Lundin <henrik.lundin@webrtc.org>
Commit-Queue: Henrik Lundin <henrik.lundin@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#37162}
This commit is contained in:
Byoungchan Lee
2022-06-09 18:14:00 +09:00
committed by WebRTC LUCI CQ
parent 6b0bedb05a
commit 1abcb1106c
4 changed files with 24 additions and 15 deletions

View File

@ -12,6 +12,7 @@
#include <iostream>
#include "rtc_base/strings/string_builder.h"
#include "rtc_base/time_utils.h"
namespace webrtc {
@ -217,9 +218,9 @@ Channel::Channel(int16_t chID)
}
if (chID >= 0) {
_saveBitStream = true;
char bitStreamFileName[500];
sprintf(bitStreamFileName, "bitStream_%d.dat", chID);
_bitStreamFile = fopen(bitStreamFileName, "wb");
rtc::StringBuilder ss;
ss.AppendFormat("bitStream_%d.dat", chID);
_bitStreamFile = fopen(ss.str().c_str(), "wb");
} else {
_saveBitStream = false;
}

View File

@ -208,7 +208,10 @@ rtc_library("audio_device_impl") {
"../../system_wrappers:metrics",
"../utility",
]
absl_deps = [ "//third_party/abseil-cpp/absl/base:core_headers" ]
absl_deps = [
"//third_party/abseil-cpp/absl/base:core_headers",
"//third_party/abseil-cpp/absl/strings:strings",
]
if (rtc_include_internal_audio_device && is_ios) {
deps += [ "../../sdk:audio_device" ]
}

View File

@ -835,7 +835,8 @@ int32_t AudioDeviceMac::PlayoutDeviceName(uint16_t index,
memset(guid, 0, kAdmMaxGuidSize);
}
return GetDeviceName(kAudioDevicePropertyScopeOutput, index, name);
return GetDeviceName(kAudioDevicePropertyScopeOutput, index,
rtc::ArrayView<char>(name, kAdmMaxDeviceNameSize));
}
int32_t AudioDeviceMac::RecordingDeviceName(uint16_t index,
@ -853,7 +854,8 @@ int32_t AudioDeviceMac::RecordingDeviceName(uint16_t index,
memset(guid, 0, kAdmMaxGuidSize);
}
return GetDeviceName(kAudioDevicePropertyScopeInput, index, name);
return GetDeviceName(kAudioDevicePropertyScopeInput, index,
rtc::ArrayView<char>(name, kAdmMaxDeviceNameSize));
}
int16_t AudioDeviceMac::RecordingDevices() {
@ -1646,9 +1648,8 @@ int32_t AudioDeviceMac::GetNumberDevices(const AudioObjectPropertyScope scope,
int32_t AudioDeviceMac::GetDeviceName(const AudioObjectPropertyScope scope,
const uint16_t index,
char* name) {
rtc::ArrayView<char> name) {
OSStatus err = noErr;
UInt32 len = kAdmMaxDeviceNameSize;
AudioDeviceID deviceIds[MaxNumberDevices];
int numberDevices = GetNumberDevices(scope, deviceIds, MaxNumberDevices);
@ -1689,21 +1690,24 @@ int32_t AudioDeviceMac::GetDeviceName(const AudioObjectPropertyScope scope,
scope, 0};
if (isDefaultDevice) {
char devName[len];
std::array<char, kAdmMaxDeviceNameSize> devName;
UInt32 len = devName.size();
WEBRTC_CA_RETURN_ON_ERR(AudioObjectGetPropertyData(usedID, &propertyAddress,
0, NULL, &len, devName));
WEBRTC_CA_RETURN_ON_ERR(AudioObjectGetPropertyData(
usedID, &propertyAddress, 0, NULL, &len, devName.data()));
sprintf(name, "default (%s)", devName);
rtc::SimpleStringBuilder ss(name);
ss.AppendFormat("default (%s)", devName.data());
} else {
if (index < numberDevices) {
usedID = deviceIds[index];
} else {
usedID = index;
}
UInt32 len = name.size();
WEBRTC_CA_RETURN_ON_ERR(AudioObjectGetPropertyData(usedID, &propertyAddress,
0, NULL, &len, name));
WEBRTC_CA_RETURN_ON_ERR(AudioObjectGetPropertyData(
usedID, &propertyAddress, 0, NULL, &len, name.data()));
}
return 0;

View File

@ -18,6 +18,7 @@
#include <atomic>
#include <memory>
#include "absl/strings/string_view.h"
#include "modules/audio_device/audio_device_generic.h"
#include "modules/audio_device/mac/audio_mixer_manager_mac.h"
#include "rtc_base/event.h"
@ -179,7 +180,7 @@ class AudioDeviceMac : public AudioDeviceGeneric {
int32_t GetDeviceName(AudioObjectPropertyScope scope,
uint16_t index,
char* name);
rtc::ArrayView<char> name);
int32_t InitDevice(uint16_t userDeviceIndex,
AudioDeviceID& deviceId,