Squash various compiler warnings

Unused-result from sensitive APIs, printf/scanf formatting types, set
but never used variables, and uninitialized variables.

Also there's one select(enum) that doesn't cover all cases.
This commit is contained in:
Phil Hord 2018-03-27 19:07:13 -07:00
parent eee7d0ddfc
commit 3f7f80e32c
9 changed files with 24 additions and 16 deletions

View File

@ -156,7 +156,7 @@ static string com_adjust_log_time(exec_context &ec, string cmdline, vector<strin
char buffer[1024];
snprintf(buffer, sizeof(buffer),
"info: log timestamps will be adjusted by %ld.%06d seconds",
"info: log timestamps will be adjusted by %ld.%06ld seconds",
time_diff.tv_sec, time_diff.tv_usec);
retval = buffer;

View File

@ -305,6 +305,8 @@ void log_msg_extra_complete()
}
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
static void sigabrt(int sig)
{
char crash_path[1024], latest_crash_path[1024];
@ -339,10 +341,10 @@ static void sigabrt(int sig)
"%s/latest-crash.log", lnav_log_crash_dir);
if ((fd = open(crash_path, O_CREAT|O_TRUNC|O_WRONLY, 0600)) != -1) {
if (log_ring.lr_frag_start < (off_t)BUFFER_SIZE) {
write(fd, &log_ring.lr_data[log_ring.lr_frag_start],
(void)write(fd, &log_ring.lr_data[log_ring.lr_frag_start],
log_ring.lr_frag_end - log_ring.lr_frag_start);
}
write(fd, log_ring.lr_data, log_ring.lr_length);
(void)write(fd, log_ring.lr_data, log_ring.lr_length);
#ifdef HAVE_EXECINFO_H
backtrace_symbols_fd(frames, frame_count, fd);
#endif
@ -395,9 +397,7 @@ static void sigabrt(int sig)
fprintf(stderr, "\nWould you like to attach a debugger? (y/N) ");
fflush(stderr);
scanf("%c", &response);
if (tolower(response) == 'y') {
if (scanf("%c", &response) > 0 && tolower(response) == 'y') {
pid_t lnav_pid = getpid();
pid_t child_pid;
@ -436,6 +436,7 @@ static void sigabrt(int sig)
_exit(1);
}
#pragma GCC diagnostic pop
void log_install_handlers(void)
{

View File

@ -849,6 +849,7 @@ string log_vtab_manager::unregister_vtab(intern_string_t name)
}
else {
auto_mem<char> sql(sqlite3_free);
__attribute((unused))
int rc;
sql = sqlite3_mprintf("DROP TABLE %s ", name.get());

View File

@ -324,7 +324,7 @@ void logfile_sub_source::text_attrs_for_line(textview_curses &lv,
chtype graph = ACS_VLINE;
if (is_first_for_file) {
if (is_last_for_file) {
graph = ACS_DIAMOND;
graph = ACS_HLINE;
}
else {
graph = ACS_ULCORNER;
@ -472,6 +472,9 @@ bool logfile_sub_source::rebuild_index(bool force)
logfile &lf = *ld.get_file();
switch (lf.rebuild_index()) {
case logfile::RR_NO_NEW_LINES:
// No changes
break;
case logfile::RR_NEW_LINES:
retval = true;
if (!this->lss_index.empty()) {

View File

@ -502,7 +502,9 @@ void rl_display_matches(void *dummy, readline_curses *rc)
{
const std::vector<std::string> &matches = rc->get_matches();
textview_curses &tc = lnav_data.ld_match_view;
unsigned long width, height;
unsigned long width;
__attribute((unused))
unsigned long height;
int max_len, cols, rows;
getmaxyx(lnav_data.ld_window, height, width);

View File

@ -103,7 +103,7 @@ regexp_match(const char *re, const char *str)
}
else {
char *cap_copy = (char *)alloca(cap->length() + 1);
int64_t i_value;
long long int i_value;
double d_value;
int end_index;
@ -112,7 +112,7 @@ regexp_match(const char *re, const char *str)
if (sscanf(cap_copy, "%lld%n", &i_value, &end_index) == 1 &&
(end_index == cap->length())) {
return i_value;
return (int64_t)i_value;
}
else if (sscanf(cap_copy, "%lf%n", &d_value, &end_index) == 1 &&
(end_index == cap->length())) {
@ -139,7 +139,7 @@ regexp_match(const char *re, const char *str)
else {
const char *cap_start = pi.get_substr_start(cap);
char *cap_copy = (char *) alloca(cap->length() + 1);
int64_t i_value;
long long int i_value;
double d_value;
int end_index;

View File

@ -204,10 +204,10 @@ attr_line_t &attr_line_t::with_ansi_string(const char *str, ...)
va_list args;
va_start(args, str);
vasprintf(formatted_str.out(), str, args);
auto ret = vasprintf(formatted_str.out(), str, args);
va_end(args);
if (formatted_str != NULL) {
if (ret >= 0 && formatted_str != NULL) {
this->al_string = formatted_str;
scrub_ansi_string(this->al_string, this->al_attrs);
}

View File

@ -517,7 +517,7 @@ int main(int argc, char *argv[])
else {
int maxfd, out_len = 0;
bool got_expected = true;
bool got_user_step;
bool got_user_step = false;
struct timeval last, now;
char out_buffer[8192];
fd_set read_fds;

View File

@ -27,8 +27,9 @@ int main(int argc, char *argv[])
FILE *file = fopen(argv[1], "r");
int row = 0;
while (!feof(file)) {
fgets(buf, sizeof(buf), file);
mvwaddstr(stdscr, row++, 0, buf);
if (0 < fgets(buf, sizeof(buf), file)) {
mvwaddstr(stdscr, row++, 0, buf);
}
}
getch();
endwin();