From 6fc2d532274ead9c903c6d94b1a513b8d9b6f677 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 22 Jun 2018 11:51:58 -0400 Subject: Remove util_bug dependency on compat.h --- src/common/compat.c | 26 -------------------------- src/common/compat.h | 8 -------- src/common/token_bucket.c | 2 +- src/common/util_bug.c | 29 ++++++++++++++++++++++++++++- src/common/util_bug.h | 12 ++++++++++-- 5 files changed, 39 insertions(+), 38 deletions(-) diff --git a/src/common/compat.c b/src/common/compat.c index 467c51d6ee..8e418f4c1d 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -493,32 +493,6 @@ tor_strtok_r_impl(char *str, const char *sep, char **lasts) return start; } -#ifdef _WIN32 -/** Take a filename and return a pointer to its final element. This - * function is called on __FILE__ to fix a MSVC nit where __FILE__ - * contains the full path to the file. This is bad, because it - * confuses users to find the home directory of the person who - * compiled the binary in their warning messages. - */ -const char * -tor_fix_source_file(const char *fname) -{ - const char *cp1, *cp2, *r; - cp1 = strrchr(fname, '/'); - cp2 = strrchr(fname, '\\'); - if (cp1 && cp2) { - r = (cp1cp. Equivalent to * *(uint16_t*)(cp), but will not cause segfaults on platforms that forbid diff --git a/src/common/compat.h b/src/common/compat.h index f91c224254..691824a2e7 100644 --- a/src/common/compat.h +++ b/src/common/compat.h @@ -92,14 +92,6 @@ char *tor_strtok_r_impl(char *str, const char *sep, char **lasts); #define tor_strtok_r(str, sep, lasts) tor_strtok_r_impl(str, sep, lasts) #endif -#ifdef _WIN32 -#define SHORT_FILE__ (tor_fix_source_file(__FILE__)) -const char *tor_fix_source_file(const char *fname); -#else -#define SHORT_FILE__ (__FILE__) -#define tor_fix_source_file(s) (s) -#endif /* defined(_WIN32) */ - /* ===== Time compatibility */ struct tm *tor_localtime_r(const time_t *timep, struct tm *result); diff --git a/src/common/token_bucket.c b/src/common/token_bucket.c index a028b08a0b..502e8eac56 100644 --- a/src/common/token_bucket.c +++ b/src/common/token_bucket.c @@ -19,6 +19,7 @@ #define TOKEN_BUCKET_PRIVATE #include "common/token_bucket.h" +#include "common/compat.h" #include "common/util_bug.h" /** @@ -252,4 +253,3 @@ token_bucket_rw_dec(token_bucket_rw_t *bucket, flags |= TB_WRITE; return flags; } - diff --git a/src/common/util_bug.c b/src/common/util_bug.c index 0e6190caf1..c68519b746 100644 --- a/src/common/util_bug.c +++ b/src/common/util_bug.c @@ -15,6 +15,7 @@ #include "lib/container/smartlist.h" #endif #include "lib/malloc/util_malloc.h" +#include "lib/string/printf.h" #ifdef __COVERITY__ int bug_macro_deadcode_dummy__ = 0; @@ -40,7 +41,7 @@ tor_end_capture_bugs_(void) return; SMARTLIST_FOREACH(bug_messages, char *, cp, tor_free(cp)); smartlist_free(bug_messages); - bug_messages = NULL; +nn bug_messages = NULL; } const smartlist_t * tor_get_captured_bug_log_(void) @@ -119,3 +120,29 @@ tor_bug_occurred_(const char *fname, unsigned int line, } #endif } + +#ifdef _WIN32 +/** Take a filename and return a pointer to its final element. This + * function is called on __FILE__ to fix a MSVC nit where __FILE__ + * contains the full path to the file. This is bad, because it + * confuses users to find the home directory of the person who + * compiled the binary in their warning messages. + */ +const char * +tor_fix_source_file(const char *fname) +{ + const char *cp1, *cp2, *r; + cp1 = strrchr(fname, '/'); + cp2 = strrchr(fname, '\\'); + if (cp1 && cp2) { + r = (cp1 -#include "common/compat.h" +#include "lib/cc/compat_compiler.h" +#include "lib/log/torlog.h" #include "lib/testsupport/testsupport.h" /* Replace assert() with a variant that sends failures to the log before @@ -192,6 +192,14 @@ void tor_bug_occurred_(const char *fname, unsigned int line, const char *func, const char *expr, int once); +#ifdef _WIN32 +#define SHORT_FILE__ (tor_fix_source_file(__FILE__)) +const char *tor_fix_source_file(const char *fname); +#else +#define SHORT_FILE__ (__FILE__) +#define tor_fix_source_file(s) (s) +#endif /* defined(_WIN32) */ + #ifdef TOR_UNIT_TESTS void tor_capture_bugs_(int n); void tor_end_capture_bugs_(void); -- cgit v1.2.3-54-g00ecf