From 597bfc6e1f2015930ae8f0249ab3763fabd4b629 Mon Sep 17 00:00:00 2001 From: Eugene Syromyatnikov Date: Wed, 23 May 2018 18:45:43 +0200 Subject: [PATCH] tests/test_nlattr.h: avoid testing cropped objects of size 1 * tests/test_nlattr.h (TEST_NLATTR_OBJECT_EX_): Check "len < sizeof(obj_)" case only if "sizeof(obj_) > 1". --- tests/test_nlattr.h | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/tests/test_nlattr.h b/tests/test_nlattr.h index be092c3b..fe681ae3 100644 --- a/tests/test_nlattr.h +++ b/tests/test_nlattr.h @@ -106,11 +106,12 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type) sizeof(obj_) - 1 > DEFAULT_STRLEN \ ? DEFAULT_STRLEN : (int) sizeof(obj_) - 1; \ /* len < sizeof(obj_) */ \ - TEST_NLATTR_((fd_), (nlh0_), (hdrlen_), \ - (init_msg_), (print_msg_), \ - (nla_type_), (nla_type_str_), \ - plen, (pattern_), plen, \ - (fallback_func)((pattern_), plen)); \ + if (plen > 0) \ + TEST_NLATTR_((fd_), (nlh0_), (hdrlen_), \ + (init_msg_), (print_msg_), \ + (nla_type_), (nla_type_str_), \ + plen, (pattern_), plen, \ + (fallback_func)((pattern_), plen)); \ /* short read of sizeof(obj_) */ \ TEST_NLATTR_((fd_), (nlh0_), (hdrlen_), \ (init_msg_), (print_msg_), \ @@ -212,15 +213,16 @@ print_nlattr(const unsigned int nla_len, const char *const nla_type) sizeof(obj_) - 1 > DEFAULT_STRLEN \ ? DEFAULT_STRLEN : (int) sizeof(obj_) - 1; \ /* len < sizeof(obj_) */ \ - TEST_NLATTR_((fd_), (nlh0_) - NLA_HDRLEN * depth_, \ - (hdrlen_) + NLA_HDRLEN * depth_, \ - (init_msg_), (print_msg_), \ - (nla_type_), (nla_type_str_), \ - plen, (pattern_), plen, \ - print_quoted_hex((pattern_), plen); \ - size_t i; \ - for (i = 0; i < depth_; ++i) \ - printf("}")); \ + if (plen > 0) \ + TEST_NLATTR_((fd_), (nlh0_) - NLA_HDRLEN * depth_, \ + (hdrlen_) + NLA_HDRLEN * depth_, \ + (init_msg_), (print_msg_), \ + (nla_type_), (nla_type_str_), \ + plen, (pattern_), plen, \ + print_quoted_hex((pattern_), plen); \ + size_t i; \ + for (i = 0; i < depth_; ++i) \ + printf("}")); \ /* short read of sizeof(obj_) */ \ TEST_NLATTR_((fd_), (nlh0_) - NLA_HDRLEN * depth_, \ (hdrlen_) + NLA_HDRLEN * depth_, \ -- 2.40.0