Skip to content

Commit

Permalink
fix(userspace/libsinsp): avoid macro redefinition
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dellaluce <jasondellaluce@gmail.com>
  • Loading branch information
jasondellaluce authored and poiana committed Feb 9, 2024
1 parent d5a0c9d commit 9932142
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 66 deletions.
58 changes: 29 additions & 29 deletions userspace/libsinsp/sinsp_filtercheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ limitations under the License.
#include <libsinsp/sinsp_filtercheck.h>
#include <libsinsp/value_parser.h>

#define STR_STORAGE_SIZE 1024
#define STRPROPERTY_STORAGE_SIZE 1024

#ifndef _GNU_SOURCE
//
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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();
Expand All @@ -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],
Expand All @@ -1110,8 +1110,8 @@ char* sinsp_filter_check::rawval_to_string(uint8_t* rawval,
strlcpy(address, "<NA>", 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();
}
Expand All @@ -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,
"<IPNET>");
return m_getpropertystr_storage.data();
default:
Expand Down Expand Up @@ -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);
Expand Down
74 changes: 37 additions & 37 deletions userspace/libsinsp/sinsp_filtercheck_reference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ limitations under the License.
#include <libsinsp/sinsp.h>
#include <libsinsp/sinsp_int.h>

#define STR_STORAGE_SIZE 1024
#define STRPROPERTY_STORAGE_SIZE 1024

using namespace std;

Expand Down Expand Up @@ -72,52 +72,52 @@ 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);
}

uint32_t len = (uint32_t)strlen(m_getpropertystr_storage.data());

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
Expand All @@ -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);
}

Expand All @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 9932142

Please sign in to comment.