Skip to content
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

Fix printing of time_t values. #1161

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions src/command_executor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,10 @@ execute_sql(exec_context& ec, const std::string& sql, std::string& alt_msg)
snprintf(row_count_buf,
sizeof(row_count_buf),
ANSI_BOLD("%'d") " row%s matched in " ANSI_BOLD(
"%ld.%03ld") " seconds",
"%lld.%03ld") " seconds",
row_count,
row_count == 1 ? "" : "s",
diff_tv.tv_sec,
(long long)diff_tv.tv_sec,
std::max((long) diff_tv.tv_usec / 1000, 1L));
retval = row_count_buf;
if (dls.has_log_time_column()) {
Expand Down Expand Up @@ -624,7 +624,7 @@ execute_file(exec_context& ec, const std::string& path_and_args, bool multiline)

vars["#"] = env_arg_name;
for (size_t lpc = 0; lpc < split_args.size(); lpc++) {
snprintf(env_arg_name, sizeof(env_arg_name), "%lu", lpc);
snprintf(env_arg_name, sizeof(env_arg_name), "%lu", (long unsigned int)lpc);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there's a z length modifier, so this should be %zu and then you don't need to cast it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct -- removing the suggested cast and using "z" format works as well for this case.

vars[env_arg_name] = split_args[lpc];
}
for (size_t lpc = 1; lpc < split_args.size(); lpc++) {
Expand Down
6 changes: 3 additions & 3 deletions src/lnav_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ com_adjust_log_time(exec_context& ec,
snprintf(
buffer,
sizeof(buffer),
"info: log timestamps will be adjusted by %ld.%06ld seconds",
time_diff.tv_sec,
"info: log timestamps will be adjusted by %lld.%06ld seconds",
(long long)time_diff.tv_sec,
(long) time_diff.tv_usec);

retval = buffer;
Expand Down Expand Up @@ -295,7 +295,7 @@ com_unix_time(exec_context& ec,
"%a %b %d %H:%M:%S %Y %z %Z",
localtime(&u_time));
len = strlen(ftime);
snprintf(ftime + len, sizeof(ftime) - len, " -- %ld", u_time);
snprintf(ftime + len, sizeof(ftime) - len, " -- %lld", (long long)u_time);
retval = std::string(ftime);
} else {
return ec.make_error("invalid unix time -- {}", args[1]);
Expand Down
4 changes: 2 additions & 2 deletions src/ptimec.hh
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ ftime_s(char* dst, off_t& off_inout, ssize_t len, const struct exttm& tm)
{
time_t t = tm2sec(&tm.et_tm);

snprintf(&dst[off_inout], len - off_inout, "%ld", t);
snprintf(&dst[off_inout], len - off_inout, "%lld", (long long)t);
off_inout = strlen(dst);
}

Expand Down Expand Up @@ -391,7 +391,7 @@ ftime_q(char* dst, off_t& off_inout, ssize_t len, const struct exttm& tm)
{
time_t t = tm2sec(&tm.et_tm);

snprintf(&dst[off_inout], len - off_inout, "%lx", t);
snprintf(&dst[off_inout], len - off_inout, "%llx", (long long)t);
off_inout = strlen(dst);
}

Expand Down