From 9932142d91c80acefc1730563358cb9795b035b0 Mon Sep 17 00:00:00 2001 From: Jason Dellaluce Date: Thu, 8 Feb 2024 17:06:45 +0000 Subject: [PATCH] fix(userspace/libsinsp): avoid macro redefinition Signed-off-by: Jason Dellaluce --- userspace/libsinsp/sinsp_filtercheck.cpp | 58 +++++++-------- .../libsinsp/sinsp_filtercheck_reference.cpp | 74 +++++++++---------- 2 files changed, 66 insertions(+), 66 deletions(-) diff --git a/userspace/libsinsp/sinsp_filtercheck.cpp b/userspace/libsinsp/sinsp_filtercheck.cpp index 9b325590cc..38cee8e498 100644 --- a/userspace/libsinsp/sinsp_filtercheck.cpp +++ b/userspace/libsinsp/sinsp_filtercheck.cpp @@ -23,7 +23,7 @@ limitations under the License. #include #include -#define STR_STORAGE_SIZE 1024 +#define STRPROPERTY_STORAGE_SIZE 1024 #ifndef _GNU_SOURCE // @@ -863,9 +863,9 @@ char* sinsp_filter_check::rawval_to_string(uint8_t* rawval, return NULL; } - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, prfmt, *(int8_t *)rawval); return m_getpropertystr_storage.data(); case PT_INT16: @@ -888,9 +888,9 @@ char* sinsp_filter_check::rawval_to_string(uint8_t* rawval, return NULL; } - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, prfmt, *(int16_t *)rawval); return m_getpropertystr_storage.data(); case PT_INT32: @@ -913,9 +913,9 @@ char* sinsp_filter_check::rawval_to_string(uint8_t* rawval, return NULL; } - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, prfmt, *(int32_t *)rawval); return m_getpropertystr_storage.data(); case PT_INT64: @@ -944,9 +944,9 @@ char* sinsp_filter_check::rawval_to_string(uint8_t* rawval, prfmt = (char*)"%" PRId64; } - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, prfmt, *(int64_t *)rawval); return m_getpropertystr_storage.data(); case PT_L4PROTO: // This can be resolved in the future @@ -970,9 +970,9 @@ char* sinsp_filter_check::rawval_to_string(uint8_t* rawval, return NULL; } - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, prfmt, *(uint8_t *)rawval); return m_getpropertystr_storage.data(); case PT_PORT: // This can be resolved in the future @@ -996,9 +996,9 @@ char* sinsp_filter_check::rawval_to_string(uint8_t* rawval, return NULL; } - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, prfmt, *(uint16_t *)rawval); return m_getpropertystr_storage.data(); case PT_UINT32: @@ -1021,9 +1021,9 @@ char* sinsp_filter_check::rawval_to_string(uint8_t* rawval, return NULL; } - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, prfmt, *(uint32_t *)rawval); return m_getpropertystr_storage.data(); case PT_UINT64: @@ -1052,9 +1052,9 @@ char* sinsp_filter_check::rawval_to_string(uint8_t* rawval, return NULL; } - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, prfmt, *(uint64_t *)rawval); return m_getpropertystr_storage.data(); case PT_CHARBUF: @@ -1070,8 +1070,8 @@ char* sinsp_filter_check::rawval_to_string(uint8_t* rawval, } else { - auto copy_len = std::min(len, (uint32_t) STR_STORAGE_SIZE); - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + auto copy_len = std::min(len, (uint32_t) STRPROPERTY_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); memcpy(m_getpropertystr_storage.data(), rawval, copy_len); m_getpropertystr_storage.data()[copy_len] = 0; return m_getpropertystr_storage.data(); @@ -1092,9 +1092,9 @@ char* sinsp_filter_check::rawval_to_string(uint8_t* rawval, return (char*)"false"; } case PT_IPV4ADDR: - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, "%" PRIu8 ".%" PRIu8 ".%" PRIu8 ".%" PRIu8, rawval[0], rawval[1], @@ -1110,8 +1110,8 @@ char* sinsp_filter_check::rawval_to_string(uint8_t* rawval, strlcpy(address, "", INET6_ADDRSTRLEN); } - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); - strlcpy(m_getpropertystr_storage.data(), address, STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); + strlcpy(m_getpropertystr_storage.data(), address, STRPROPERTY_STORAGE_SIZE); return m_getpropertystr_storage.data(); } @@ -1130,15 +1130,15 @@ char* sinsp_filter_check::rawval_to_string(uint8_t* rawval, } case PT_DOUBLE: - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, "%.1lf", *(double*)rawval); return m_getpropertystr_storage.data(); case PT_IPNET: - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, ""); return m_getpropertystr_storage.data(); default: @@ -1167,8 +1167,8 @@ char* sinsp_filter_check::tostring(sinsp_evt* evt) res += rawval_to_string(val.ptr, m_field->m_type, m_field->m_print_format, val.len); } res += ")"; - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); - strlcpy(m_getpropertystr_storage.data(), res.c_str(), STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); + strlcpy(m_getpropertystr_storage.data(), res.c_str(), STRPROPERTY_STORAGE_SIZE); return m_getpropertystr_storage.data(); } return rawval_to_string(m_extracted_values[0].ptr, m_field->m_type, m_field->m_print_format, m_extracted_values[0].len); diff --git a/userspace/libsinsp/sinsp_filtercheck_reference.cpp b/userspace/libsinsp/sinsp_filtercheck_reference.cpp index c4c5e84e71..e5b11a6fa9 100644 --- a/userspace/libsinsp/sinsp_filtercheck_reference.cpp +++ b/userspace/libsinsp/sinsp_filtercheck_reference.cpp @@ -20,7 +20,7 @@ limitations under the License. #include #include -#define STR_STORAGE_SIZE 1024 +#define STRPROPERTY_STORAGE_SIZE 1024 using namespace std; @@ -72,44 +72,44 @@ char* sinsp_filter_check_reference::format_bytes(double val, uint32_t str_len, b if(val > (1024LL * 1024 * 1024 * 1024 * 1024)) { - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, pr_fmt, str_len - 1, (val) / (1024LL * 1024 * 1024 * 1024 * 1024), 'P'); } else if(val > (1024LL * 1024 * 1024 * 1024)) { - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, pr_fmt, str_len - 1, (val) / (1024LL * 1024 * 1024 * 1024), 'T'); } else if(val > (1024LL * 1024 * 1024)) { - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, pr_fmt, str_len - 1, (val) / (1024LL * 1024 * 1024), 'G'); } else if(val > (1024 * 1024)) { - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, pr_fmt, str_len - 1, (val) / (1024 * 1024), 'M'); } else if(val > 1024) { - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, pr_fmt, str_len - 1, (val) / (1024), 'K'); } else { - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, pr_fmt, str_len, val, 0); } @@ -117,7 +117,7 @@ char* sinsp_filter_check_reference::format_bytes(double val, uint32_t str_len, b if(len > str_len) { - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); memmove(m_getpropertystr_storage.data(), m_getpropertystr_storage.data() + len - str_len, str_len + 1); // include trailing \0 @@ -137,60 +137,60 @@ char* sinsp_filter_check_reference::format_time(uint64_t val, uint32_t str_len) { if(val >= 3600 * ONE_SECOND_IN_NS) { - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, "%.2u:%.2u:%.2u", (unsigned int)(val / (3600 * ONE_SECOND_IN_NS)), (unsigned int)((val / (60 * ONE_SECOND_IN_NS)) % 60 ), (unsigned int)((val / ONE_SECOND_IN_NS) % 60)); } else if(val >= 60 * ONE_SECOND_IN_NS) { - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, "%u:%u", (unsigned int)(val / (60 * ONE_SECOND_IN_NS)), (unsigned int)((val / ONE_SECOND_IN_NS) % 60)); } else if(val >= ONE_SECOND_IN_NS) { - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, "%u.%02us", (unsigned int)(val / ONE_SECOND_IN_NS), (unsigned int)((val % ONE_SECOND_IN_NS) / 10000000)); } else if(val >= ONE_SECOND_IN_NS / 100) { - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, "%ums", (unsigned int)(val / (ONE_SECOND_IN_NS / 1000))); } else if(val >= ONE_SECOND_IN_NS / 1000) { - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, "%u.%02ums", (unsigned int)(val / (ONE_SECOND_IN_NS / 1000)), (unsigned int)((val % ONE_MILLISECOND_IN_NS) / 10000)); } else if(val >= ONE_SECOND_IN_NS / 100000) { - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, "%uus", (unsigned int)(val / (ONE_SECOND_IN_NS / 1000000))); } else if(val >= ONE_SECOND_IN_NS / 1000000) { - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, "%u.%02uus", (unsigned int)(val / (ONE_SECOND_IN_NS / 1000000)), (unsigned int)((val % ONE_MICROSECOND_IN_NS) / 10)); } else { - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, "%uns", (unsigned int)val); } @@ -199,7 +199,7 @@ char* sinsp_filter_check_reference::format_time(uint64_t val, uint32_t str_len) { uint32_t padding_size = str_len - reslen; - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); memmove(m_getpropertystr_storage.data() + padding_size, m_getpropertystr_storage.data(), str_len + 1); @@ -256,9 +256,9 @@ char* sinsp_filter_check_reference::print_double(uint8_t* rawval, uint32_t str_l if(m_print_format == PF_ID) { - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, "%*lf", str_len, val); return m_getpropertystr_storage.data(); } @@ -312,9 +312,9 @@ char* sinsp_filter_check_reference::print_int(uint8_t* rawval, uint32_t str_len) if(m_print_format == PF_ID) { - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, "%*" PRId64, str_len, val); return m_getpropertystr_storage.data(); } @@ -375,9 +375,9 @@ char* sinsp_filter_check_reference::tostring_nice(sinsp_evt* evt, dval /= m_cnt; } - m_getpropertystr_storage.resize(STR_STORAGE_SIZE); + m_getpropertystr_storage.resize(STRPROPERTY_STORAGE_SIZE); snprintf(m_getpropertystr_storage.data(), - STR_STORAGE_SIZE, + STRPROPERTY_STORAGE_SIZE, "%*.2lf", str_len, dval); return m_getpropertystr_storage.data(); }