assert(l_file == (struct log_file *) 0xDEFACED);
sv_pushed = true;
- return 123;
+ return 0;
}
static bool sv_flushed;
assert(file == (struct log_file *) 0xDEFACED);
sv_flushed = true;
- return 321;
+ return 0;
}
struct fd_info G_fdi;
struct fd_info **fdi_arr = NULL;
fdi_array_free(&fdi_arr);
- fdi_arr = calloc(3, sizeof **fdi_arr);
+ fdi_arr = calloc(3, sizeof *fdi_arr);
assert(fdi_arr);
fdi_arr[0] = &G_fdi;
expect_free1 = fdi_arr;
expect_free2 = &G_fdi;
fdi_array_free(&fdi_arr);
- fdi_arr = calloc(3, sizeof **fdi_arr);
+ fdi_arr = calloc(3, sizeof *fdi_arr);
assert(fdi_arr);
fdi_arr[1] = &G_fdi;
expect_free1 = fdi_arr;
assert(expected->header.pid == lem.header.pid);
assert(expected->header.tid == lem.header.tid);
- assert(!strcmp(log_buffer_get_tag(&expected->header), log_buffer_get_tag(&lem.header)));
- assert(!strcmp(log_buffer_get_message(&expected->header), log_buffer_get_message(&lem.header)));
+
+ const char *const tag_expected = log_buffer_get_tag(&expected->header);
+ const char *const tag_actual = log_buffer_get_tag(&lem.header);
+ const char *const msg_expected = log_buffer_get_message(&expected->header);
+ const char *const msg_actual = log_buffer_get_message(&lem.header);
+ assert(tag_expected);
+ assert(tag_actual);
+ assert(msg_expected);
+ assert(msg_actual);
+ assert(!strcmp(tag_expected, tag_actual));
+ assert(!strcmp(msg_expected, msg_actual));
}
int main()
assert(LOG_ID_MAIN == 0);
for (int i = 1; i < LOG_ID_MAX; ++i) {
char key[MAX_CONF_KEY_LEN];
- snprintf(key, sizeof key, "%s_write_sock", log_name_by_id((log_id_t)i));
+ assert(snprintf(key, sizeof key, "%s_write_sock", log_name_by_id((log_id_t)i)) > 0);
log_config_set(&conf, key, "/foo");
}
called_recv_pipe = 0; \
} while (0)
- const size_t ITERATIONS_TO_REACH_MIN_TIMEOUT = 2 + log2(DEFAULT_WAIT_PIPE_MS / MIN_WAIT_PIPE_MS);
+ const size_t ITERATIONS_TO_REACH_MIN_TIMEOUT = 2 + (int) log2((float) DEFAULT_WAIT_PIPE_MS / MIN_WAIT_PIPE_MS);
for (size_t i = 0; i < ITERATIONS_TO_REACH_MIN_TIMEOUT; ++i)
TC(0, 0, 1, 13, -1, "xx", 1, 1, 1);
assert(expected_timeout == MIN_WAIT_PIPE_MS);
assert(!__log_limiter_create(&conf));
struct rule *r = NULL;
- assert(!__log_limiter_dump_rule(&r, NULL, 0));
+ char buffer[10];
+ assert(!__log_limiter_dump_rule(&r, buffer, sizeof buffer));
assert(r == NULL);
log_config_set(&conf, "limiter|*|*" , "allow");
assert(src == (void *) 0xBA5EBALL);
assert(n == sizeof(struct logger_entry));
+ return dest;
}
static bool fail_snprintf;
assert(file_prep);
for (size_t i = 0; i < lines_cnt; ++i) {
- fputs(lines[i], file_prep);
- fputc('\n', file_prep);
+ assert(fputs(lines[i], file_prep) >= 0);
+ assert(fputc('\n', file_prep) == '\n');
}
}
#define PREPARE_FILE(lines) _prepare_file(lines, NELEMS(lines))
assert(EXIT_SUCCESS == copy_file_with_exceptions(TMPFILE_PATH, &kv));
#undef TEST_FAIL
+
+ free(kv.keys);
+ free(kv.values);
}
void test_handle_clear()
for (size_t i = 0; i < tests_n; ++i) {
log_set_print_format(format, tests[i].format);
entry.header.default_send_ts_type = tests[i].send_ts_type;
- log_print_log_line(format, 0, &entry.header);
+ assert(log_print_log_line(format, 0, &entry.header) > 0);
assert(!strcmp(tests[i].result, buffer));
}
// C
#include <assert.h>
+#include <stddef.h>
// POSIX
#include <time.h>
ale->nsec_sent = 8;
ale->pid = 13;
ale->tid = 21;
- sprintf(ale->msg, "%c%s%c%s%c"
+ assert(snprintf(ale->msg, sizeof buffer - offsetof(typeof(*ale), msg), "%c%s%c%s%c"
, (char)DLOG_ERROR
, "TAG", '\0'
, "MSG", '\0'
- );
+ ) > 0);
struct logger_entry_with_msg lewm;
parse_androidlogger_message(ale, &lewm.header, 9 + sizeof *ale);
static inline void close_fd(const int *fd)
{
assert(fd);
- if (*fd != -1)
- close(*fd);
+ if (*fd >= 0)
+ assert(!close(*fd));
}
// limit values same as in loglimiter
if (r < 0) {
int ret = -errno;
perror("snprintf error");
- close(fd);
+ assert(!close(fd));
return ret;
}