[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Fix style and compilation in log_test_helpers
commit c01f9d9ffe03d5c46833df477fcf2a4bd36dd389
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Fri Oct 2 13:03:43 2015 +0200
Fix style and compilation in log_test_helpers
---
src/test/log_test_helpers.c | 37 +++++++++++++++++++++++++------------
src/test/log_test_helpers.h | 7 +++++--
2 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/src/test/log_test_helpers.c b/src/test/log_test_helpers.c
index 42778d4..925f0f1 100644
--- a/src/test/log_test_helpers.c
+++ b/src/test/log_test_helpers.c
@@ -33,8 +33,8 @@ mock_clean_saved_logs(void)
saved_logs = NULL;
}
-char *
-mock_saved_log_at(int ix)
+static mock_saved_log_entry_t *
+mock_get_log_entry(int ix)
{
int saved_log_count = mock_saved_log_number();
if(ix < 0) {
@@ -42,21 +42,29 @@ mock_saved_log_at(int ix)
}
if (saved_log_count <= ix)
+ return NULL;
+
+ return smartlist_get(saved_logs, ix);
+}
+
+const char *
+mock_saved_log_at(int ix)
+{
+ mock_saved_log_entry_t *ent = mock_get_log_entry(ix);
+ if (ent)
+ return ent->generated_msg;
+ else
return "";
- return ((mock_saved_log_entry_t *)smartlist_get(saved_logs, ix))->generated_msg;
}
int
mock_saved_severity_at(int ix)
{
- int saved_log_count = mock_saved_log_number();
- if(ix < 0) {
- ix = saved_log_count + ix;
- }
-
- if (saved_log_count <= ix)
+ mock_saved_log_entry_t *ent = mock_get_log_entry(ix);
+ if (ent)
+ return ent->severity;
+ else
return -1;
- return ((mock_saved_log_entry_t *)smartlist_get(saved_logs, ix))->severity;
}
int
@@ -74,11 +82,15 @@ mock_saved_logs(void)
}
void
-mock_saving_logv(int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap)
+mock_saving_logv(int severity, log_domain_mask_t domain,
+ const char *funcname, const char *suffix,
+ const char *format, va_list ap)
{
+ (void)domain;
char *buf = tor_malloc_zero(10240);
int n;
n = tor_vsnprintf(buf,10240,format,ap);
+ tor_assert(n < 10240-1);
buf[n]='\n';
buf[n+1]='\0';
@@ -87,7 +99,8 @@ mock_saving_logv(int severity, log_domain_mask_t domain, const char *funcname, c
e->funcname = funcname;
e->suffix = suffix;
e->format = format;
- e->generated_msg = buf;
+ e->generated_msg = tor_strdup(buf);
+ tor_free(buf);
if (!saved_logs)
saved_logs = smartlist_new();
diff --git a/src/test/log_test_helpers.h b/src/test/log_test_helpers.h
index 789bfe4..4822ce5 100644
--- a/src/test/log_test_helpers.h
+++ b/src/test/log_test_helpers.h
@@ -15,12 +15,15 @@ typedef struct mock_saved_log_entry_t {
struct mock_saved_log_entry_t *next;
} mock_saved_log_entry_t;
-void mock_saving_logv(int severity, log_domain_mask_t domain, const char *funcname, const char *suffix, const char *format, va_list ap);
+void mock_saving_logv(int severity, log_domain_mask_t domain,
+ const char *funcname, const char *suffix,
+ const char *format, va_list ap)
+ CHECK_PRINTF(5, 0);
void mock_clean_saved_logs(void);
const smartlist_t *mock_saved_logs(void);
int setup_capture_of_logs(int new_level);
void teardown_capture_of_logs(int prev);
-char *mock_saved_log_at(int ix);
+const char *mock_saved_log_at(int ix);
int mock_saved_severity_at(int ix);
int mock_saved_log_number(void);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits