Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8b24176e authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "gd/common: Replace variable length array"

parents 3961257b 755487bd
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -98,6 +98,7 @@ std::string ToString(uint64_t value);
std::optional<bool> BoolFromString(const std::string& str);
std::string ToString(bool value);

// Migrate this method to std::format when C++20 becomes available
// printf like formatting to std::string
// format must contains format information, to print a string use StringFormat("%s", str)
template <typename... Args>
@@ -105,8 +106,8 @@ std::string StringFormat(const std::string& format, Args... args) {
  auto size = std::snprintf(nullptr, 0, format.c_str(), args...);
  ASSERT_LOG(size >= 0, "return value %d, error %d, text '%s'", size, errno, strerror(errno));
  // Add 1 for terminating null byte
  char buffer[size + 1];
  auto actual_size = std::snprintf(buffer, sizeof(buffer), format.c_str(), args...);
  std::vector<char> buffer(size + 1);
  auto actual_size = std::snprintf(buffer.data(), buffer.size(), format.c_str(), args...);
  ASSERT_LOG(
      size == actual_size,
      "asked size %d, actual size %d, error %d, text '%s'",
@@ -115,7 +116,7 @@ std::string StringFormat(const std::string& format, Args... args) {
      errno,
      strerror(errno));
  // Exclude the terminating null byte
  return std::string(buffer, size);
  return std::string(buffer.data(), size);
}

inline std::string StringFormatTime(const std::string& format, const struct std::tm& tm) {