Skip to content

Fix compilation with newer compilers: GCC-14 and CLANG-16 #759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix GCC-14 compilation warning.
bustub/src/type/timestamp_type.cpp: In member function ‘virtual std::string bustub::TimestampType::ToString(const bustub::Value&) const’:
bustub/src/type/timestamp_type.cpp:130:29: error: ‘%02d’ directive output may be truncated writing between 2 and 10 bytes into a region of size 5 [-Werror=format-truncation=]
  130 |   snprintf(zone, zone_len, "%02d", tz);  // NOLINT
        |                             ^~~~
bustub/src/type/timestamp_type.cpp:130:28: note: directive argument in the range [0, 2147483647]
          130 |   snprintf(zone, zone_len, "%02d", tz);  // NOLINT
                |                            ^~~~~~
bustub/src/type/timestamp_type.cpp:130:11: note: ‘snprintf’ output between 3 and 11 bytes into a destination of size 5
                  130 |   snprintf(zone, zone_len, "%02d", tz);  // NOLINT
  • Loading branch information
gladk committed Oct 15, 2024
commit 285738fcb44f97cd55921783985e0194efbbba0b
4 changes: 2 additions & 2 deletions src/type/timestamp_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ auto TimestampType::ToString(const Value &val) const -> std::string {
tm /= 32;
auto month = static_cast<uint16_t>(tm);
const size_t date_str_len = 30;
const size_t zone_len = 5;
const size_t zone_len = 6;
char str[date_str_len];
char zone[zone_len];
snprintf(str, date_str_len, "%04d-%02d-%02d %02d:%02d:%02d.%06d", year, month, day, hour, min, sec, micro);
Expand All @@ -127,7 +127,7 @@ auto TimestampType::ToString(const Value &val) const -> std::string {
if (tz < 0) {
tz = -tz;
}
snprintf(zone, zone_len, "%02d", tz); // NOLINT
snprintf(zone, std::min(zone_len, sizeof(zone)), "%02d", tz); // NOLINT
str[27] = 0;
return std::string(std::string(str) + std::string(zone));
}
Expand Down