Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/include/opentelemetry/common/kv_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class KeyValueProperties
nostd::unique_ptr<const char[]> CopyStringToPointer(nostd::string_view str)
{
char *temp = new char[str.size() + 1];
memcpy(temp, str.data(), str.size());
std::memcpy(temp, str.data(), str.size());
temp[str.size()] = '\0';
return nostd::unique_ptr<const char[]>(temp);
}
Expand Down
4 changes: 2 additions & 2 deletions api/include/opentelemetry/common/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ class StringUtil
{
return nostd::string_view();
}
while (left <= right && isspace(str[left]))
while (left <= right && std::isspace(str[left]))
{
left++;
}
while (left <= right && isspace(str[right]))
while (left <= right && std::isspace(str[right]))
{
right--;
}
Expand Down
14 changes: 10 additions & 4 deletions api/include/opentelemetry/trace/span_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ class SpanId final
SpanId() noexcept = default;

// Creates a SpanId with the given ID.
explicit SpanId(nostd::span<const uint8_t, kSize> id) noexcept { memcpy(rep_, id.data(), kSize); }
explicit SpanId(nostd::span<const uint8_t, kSize> id) noexcept
{
std::memcpy(rep_, id.data(), kSize);
}

// Populates the buffer with the lowercase base16 representation of the ID.
void ToLowerBase16(nostd::span<char, 2 * kSize> buffer) const noexcept
Expand All @@ -42,21 +45,24 @@ class SpanId final
return nostd::span<const uint8_t, kSize>(rep_);
}

bool operator==(const SpanId &that) const noexcept { return memcmp(rep_, that.rep_, kSize) == 0; }
bool operator==(const SpanId &that) const noexcept
{
return std::memcmp(rep_, that.rep_, kSize) == 0;
}

bool operator!=(const SpanId &that) const noexcept { return !(*this == that); }

// Returns false if the SpanId is all zeros.
bool IsValid() const noexcept
{
static constexpr uint8_t kEmptyRep[kSize] = {0};
return memcmp(rep_, kEmptyRep, kSize) != 0;
return std::memcmp(rep_, kEmptyRep, kSize) != 0;
}

// Copies the opaque SpanId data to dest.
void CopyBytesTo(nostd::span<uint8_t, kSize> dest) const noexcept
{
memcpy(dest.data(), rep_, kSize);
std::memcpy(dest.data(), rep_, kSize);
}

private:
Expand Down
6 changes: 3 additions & 3 deletions api/include/opentelemetry/trace/trace_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TraceId final
// Creates a TraceId with the given ID.
explicit TraceId(nostd::span<const uint8_t, kSize> id) noexcept
{
memcpy(rep_, id.data(), kSize);
std::memcpy(rep_, id.data(), kSize);
}

// Populates the buffer with the lowercase base16 representation of the ID.
Expand All @@ -50,7 +50,7 @@ class TraceId final

bool operator==(const TraceId &that) const noexcept
{
return memcmp(rep_, that.rep_, kSize) == 0;
return std::memcmp(rep_, that.rep_, kSize) == 0;
}

bool operator!=(const TraceId &that) const noexcept { return !(*this == that); }
Expand All @@ -61,7 +61,7 @@ class TraceId final
// Copies the opaque TraceId data to dest.
void CopyBytesTo(nostd::span<uint8_t, kSize> dest) const noexcept
{
memcpy(dest.data(), rep_, kSize);
std::memcpy(dest.data(), rep_, kSize);
}

private:
Expand Down
5 changes: 4 additions & 1 deletion api/include/opentelemetry/trace/trace_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,10 @@ class OPENTELEMETRY_EXPORT TraceState
}
#endif

static bool IsLowerCaseAlphaOrDigit(char c) noexcept { return isdigit(c) || islower(c); }
static bool IsLowerCaseAlphaOrDigit(char c) noexcept
{
return std::isdigit(c) || std::islower(c);
}

private:
// Store entries in a C-style array to avoid using std::array or std::vector.
Expand Down
3 changes: 2 additions & 1 deletion api/test/common/string_util_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ TEST(StringUtilTest, TrimStringWithIndex)
{" k1=v1 ", "k1=v1"}, {" ", ""}};
for (auto &testcase : testcases)
{
EXPECT_EQ(StringUtil::Trim(testcase.input, 0, strlen(testcase.input) - 1), testcase.expected);
EXPECT_EQ(StringUtil::Trim(testcase.input, 0, std::strlen(testcase.input) - 1),
testcase.expected);
}
}

Expand Down
4 changes: 2 additions & 2 deletions api/test/core/version_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
TEST(VersionTest, Consistency)
{
char expected[10];
snprintf(expected, sizeof(expected), "%d.%d.%d", OPENTELEMETRY_VERSION_MAJOR,
OPENTELEMETRY_VERSION_MINOR, OPENTELEMETRY_VERSION_PATCH);
std::snprintf(expected, sizeof(expected), "%d.%d.%d", OPENTELEMETRY_VERSION_MAJOR,
OPENTELEMETRY_VERSION_MINOR, OPENTELEMETRY_VERSION_PATCH);

std::string actual = OPENTELEMETRY_VERSION;
/* OPENTELEMETRY_VERSION may contain a -dev suffix */
Expand Down
2 changes: 1 addition & 1 deletion api/test/trace/span_id_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ TEST(SpanIdTest, CopyBytesTo)
SpanId id(src);
uint8_t buf[8];
id.CopyBytesTo(buf);
EXPECT_TRUE(memcmp(src, buf, 8) == 0);
EXPECT_TRUE(std::memcmp(src, buf, 8) == 0);
}
} // namespace
2 changes: 1 addition & 1 deletion api/test/trace/trace_id_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ TEST(TraceIdTest, CopyBytesTo)
TraceId id(src);
uint8_t buf[TraceId::kSize];
id.CopyBytesTo(buf);
EXPECT_TRUE(memcmp(src, buf, sizeof(buf)) == 0);
EXPECT_TRUE(std::memcmp(src, buf, sizeof(buf)) == 0);
}
} // namespace
2 changes: 1 addition & 1 deletion examples/batch/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ int main(int /* argc */, char ** /* argv */)

// Shutdown and drain queue
StartAndEndSpans();
printf("Shutting down and draining queue.... \n");
std::printf("Shutting down and draining queue.... \n");
std::this_thread::sleep_for(std::chrono::milliseconds(2000));

// We invoke the processor destructor
Expand Down
34 changes: 17 additions & 17 deletions examples/configuration/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ class CheckerLogHandler : public opentelemetry::sdk::common::internal_log::LogHa
case opentelemetry::sdk::common::internal_log::LogLevel::None:
break;
case opentelemetry::sdk::common::internal_log::LogLevel::Error:
fprintf(stdout, "[ERROR] %s\n", msg);
std::fprintf(stdout, "[ERROR] %s\n", msg);
break;
case opentelemetry::sdk::common::internal_log::LogLevel::Warning:
fprintf(stdout, "[WARNING] %s\n", msg);
std::fprintf(stdout, "[WARNING] %s\n", msg);
break;
case opentelemetry::sdk::common::internal_log::LogLevel::Info:
fprintf(stdout, "[INFO] %s\n", msg);
std::fprintf(stdout, "[INFO] %s\n", msg);
break;
case opentelemetry::sdk::common::internal_log::LogLevel::Debug:
fprintf(stdout, "[DEBUG] %s\n", msg);
std::fprintf(stdout, "[DEBUG] %s\n", msg);
break;
}
}
Expand All @@ -115,12 +115,12 @@ void PrintModelParsedForTesting(bool pass)
{
if (pass)
{
fprintf(stdout, "MODEL PARSED\n");
std::fprintf(stdout, "MODEL PARSED\n");
}
else
{
fprintf(stdout, "FAILED TO PARSE MODEL\n");
exit(1);
std::fprintf(stdout, "FAILED TO PARSE MODEL\n");
std::exit(1);
}
}
}
Expand All @@ -131,12 +131,12 @@ void PrintSdkCreatedForTesting(bool pass)
{
if (pass)
{
fprintf(stdout, "SDK CREATED\n");
std::fprintf(stdout, "SDK CREATED\n");
}
else
{
fprintf(stdout, "FAILED TO CREATE SDK\n");
exit(2);
std::fprintf(stdout, "FAILED TO CREATE SDK\n");
std::exit(2);
}
}
}
Expand Down Expand Up @@ -259,7 +259,7 @@ void CleanupOtel()
}
} // namespace

static void usage(FILE *out)
static void usage(std::FILE *out)
{
static const char *msg =
"Usage: example_yaml [options]\n"
Expand All @@ -284,7 +284,7 @@ static void usage(FILE *out)
" --no-registry\n"
" Run with an empty registry\n";

fprintf(out, "%s", msg);
std::fprintf(out, "%s", msg);
}

static int parse_args(int argc, char *argv[])
Expand All @@ -294,15 +294,15 @@ static int parse_args(int argc, char *argv[])

while (remaining_argc > 0)
{
if (strcmp(*remaining_argv, "--help") == 0)
if (std::strcmp(*remaining_argv, "--help") == 0)
{
opt_help = true;
return 0;
}

if (remaining_argc >= 2)
{
if (strcmp(*remaining_argv, "--yaml") == 0)
if (std::strcmp(*remaining_argv, "--yaml") == 0)
{
remaining_argc--;
remaining_argv++;
Expand All @@ -313,23 +313,23 @@ static int parse_args(int argc, char *argv[])
}
}

if (strcmp(*remaining_argv, "--debug") == 0)
if (std::strcmp(*remaining_argv, "--debug") == 0)
{
remaining_argc--;
remaining_argv++;
opt_debug = true;
continue;
}

if (strcmp(*remaining_argv, "--test") == 0)
if (std::strcmp(*remaining_argv, "--test") == 0)
{
remaining_argc--;
remaining_argv++;
opt_test = true;
continue;
}

if (strcmp(*remaining_argv, "--no-registry") == 0)
if (std::strcmp(*remaining_argv, "--no-registry") == 0)
{
remaining_argc--;
remaining_argv++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

#pragma once
#include <cstring>
#include <map>

#if defined(OPENTELEMETRY_ATTRIBUTE_TIMESTAMP_PREVIEW)
Expand Down Expand Up @@ -225,7 +226,7 @@ static inline std::string ToLowerBase16(const T &id)
static inline bool CopySpanIdToActivityId(const opentelemetry::trace::SpanId &span_id,
GUID &outGuid)
{
memset(&outGuid, 0, sizeof(outGuid));
std::memset(&outGuid, 0, sizeof(outGuid));
if (!span_id.IsValid())
{
return false;
Expand Down
10 changes: 6 additions & 4 deletions exporters/etw/include/opentelemetry/exporters/etw/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

#include <algorithm>
#include <chrono>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <locale>
Expand Down Expand Up @@ -260,7 +262,7 @@ static inline std::string formatUtcTimestampNsAsISO8601(int64_t timestampNs)
tm tm;
if (::_gmtime64_s(&tm, &seconds) != 0)
{
memset(&tm, 0, sizeof(tm));
std::memset(&tm, 0, sizeof(tm));
}
::_snprintf_s(buf, _TRUNCATE, "%04d-%02d-%02dT%02d:%02d:%02d.%09dZ", 1900 + tm.tm_year,
1 + tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, nanoseconds);
Expand All @@ -271,10 +273,10 @@ static inline std::string formatUtcTimestampNsAsISO8601(int64_t timestampNs)
bool valid = (gmtime_r(&seconds, &tm) != NULL);
if (!valid)
{
memset(&tm, 0, sizeof(tm));
std::memset(&tm, 0, sizeof(tm));
}
(void)snprintf(buf, sizeof(buf), "%04d-%02d-%02dT%02d:%02d:%02d.%09dZ", 1900 + tm.tm_year,
1 + tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, nanoseconds);
(void)std::snprintf(buf, sizeof(buf), "%04d-%02d-%02dT%02d:%02d:%02d.%09dZ", 1900 + tm.tm_year,
1 + tm.tm_mon, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, nanoseconds);
#endif
return buf;
}
Expand Down
6 changes: 3 additions & 3 deletions exporters/etw/include/opentelemetry/exporters/etw/uuid.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ struct UUID
this->Data1 = uuid.Data1;
this->Data2 = uuid.Data2;
this->Data3 = uuid.Data3;
memcpy(&(this->Data4[0]), &(uuid.Data4[0]), sizeof(uuid.Data4));
std::memcpy(&(this->Data4[0]), &(uuid.Data4[0]), sizeof(uuid.Data4));
}

#ifdef _WIN32
Expand Down Expand Up @@ -382,7 +382,7 @@ struct UUID
bool operator==(UUID const &other) const
{
return Data1 == other.Data1 && Data2 == other.Data2 && Data3 == other.Data3 &&
(0 == memcmp(Data4, other.Data4, sizeof(Data4)));
(0 == std::memcmp(Data4, other.Data4, sizeof(Data4)));
}

/// <summary>
Expand All @@ -392,7 +392,7 @@ struct UUID
bool operator<(UUID const &other) const
{
return Data1 < other.Data1 || Data2 < other.Data2 || Data3 == other.Data3 ||
(memcmp(Data4, other.Data4, sizeof(Data4)) < 0);
(std::memcmp(Data4, other.Data4, sizeof(Data4)) < 0);
}
};
#pragma pack(pop) /* restore original alignment from stack */
Expand Down
Loading
Loading