diff --git a/wireshark.h b/wireshark.h index 3bf40cdb39..dcd426606a 100644 --- a/wireshark.h +++ b/wireshark.h @@ -44,7 +44,6 @@ #include #include -#include #include #include diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index f5c2eb7853..57ca848826 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -77,6 +77,7 @@ set(WSUTIL_PUBLIC_HEADERS ws_mempbrk_int.h ws_pipe.h ws_roundup.h + ws_return.h wsgcrypt.h wsjson.h wslog.h diff --git a/wsutil/to_str.c b/wsutil/to_str.c index 8aabf426b6..98ec094edc 100644 --- a/wsutil/to_str.c +++ b/wsutil/to_str.c @@ -21,6 +21,7 @@ #include #include #include +#include /* * If a user _does_ pass in a too-small buffer, this is probably diff --git a/wsutil/ws_return.h b/wsutil/ws_return.h new file mode 100644 index 0000000000..6f4034b6f1 --- /dev/null +++ b/wsutil/ws_return.h @@ -0,0 +1,46 @@ +/* + * Wireshark - Network traffic analyzer + * By Gerald Combs + * Copyright 1998 Gerald Combs + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef __WS_RETURN_H__ +#define __WS_RETURN_H__ + +#include +#include + +#define ws_warn_zero_len() ws_warning("Zero length passed to %s", __func__) + +#define ws_warn_null_ptr() ws_warning("Null pointer passed to %s", __func__) + + +#define ws_return_str_if_zero(scope, len) \ + do { \ + if (!(len)) { \ + ws_warn_zero_len(); \ + return wmem_strdup(scope, "(zero length)"); \ + } \ + } while (0) + + +#define ws_return_str_if_null(scope, ptr) \ + do { \ + if (!(ptr)) { \ + ws_warn_null_ptr(); \ + return wmem_strdup(scope, "(null pointer)"); \ + } \ + } while (0) + + +#define ws_return_ptr_if_null(ptr, val) \ + do { \ + if (!(ptr)) { \ + ws_warn_null_ptr(); \ + return (val); \ + } \ + } while (0) + +#endif /* WS_RETURN_H_ */ diff --git a/wsutil/wslog.h b/wsutil/wslog.h index 6f1333e030..5a074c256b 100644 --- a/wsutil/wslog.h +++ b/wsutil/wslog.h @@ -11,16 +11,15 @@ #ifndef __WSLOG_H__ #define __WSLOG_H__ -#include #include #include #include +#include -#include +#include +#include #include -#include - #ifdef WS_LOG_DOMAIN #define _LOG_DOMAIN WS_LOG_DOMAIN #else @@ -297,38 +296,6 @@ void ws_logv_full(const char *domain, enum ws_log_level level, #define ws_noisy(...) _LOG_DEBUG(LOG_LEVEL_NOISY, __VA_ARGS__) -#define ws_warn_zero_len() ws_warning("Zero length passed to %s", __func__) - -#define ws_warn_null_ptr() ws_warning("Null pointer passed to %s", __func__) - - -#define ws_return_str_if_zero(scope, len) \ - do { \ - if (!(len)) { \ - ws_warn_zero_len(); \ - return wmem_strdup(scope, "(zero length)"); \ - } \ - } while (0) - - -#define ws_return_str_if_null(scope, ptr) \ - do { \ - if (!(ptr)) { \ - ws_warn_null_ptr(); \ - return wmem_strdup(scope, "(null pointer)"); \ - } \ - } while (0) - - -#define ws_return_ptr_if_null(ptr, val) \ - do { \ - if (!(ptr)) { \ - ws_warn_null_ptr(); \ - return (val); \ - } \ - } while (0) - - /** This function is called to log a buffer (bytes array). * * Accepts an optional 'msg' argument to provide a description.