Source
/* zbx_trim_integer() stripped one '+' sign, so there's more than one '+' sign in the 'text' argument */
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
ZBX_VECTOR_IMPL(var, zbx_variant_t)
static void *zbx_variant_data_bin_copy(const void *bin)
{
zbx_uint32_t size;
void *value_bin;
memcpy(&size, bin, sizeof(size));
value_bin = zbx_malloc(NULL, size + sizeof(size));
memcpy(value_bin, bin, size + sizeof(size));
return value_bin;
}
void *zbx_variant_data_bin_create(const void *data, zbx_uint32_t size)
{
void *value_bin;
value_bin = zbx_malloc(NULL, size + sizeof(size));
memcpy(value_bin, &size, sizeof(size));
memcpy((unsigned char *)value_bin + sizeof(size), data, size);
return value_bin;
}
zbx_uint32_t zbx_variant_data_bin_get(const void *bin, const void ** const data)
{
zbx_uint32_t size;
memcpy(&size, bin, sizeof(zbx_uint32_t));
if (NULL != data)
*data = (const unsigned char *)bin + sizeof(size);
return size;
}
void zbx_variant_clear(zbx_variant_t *value)
{
switch (value->type)
{
case ZBX_VARIANT_STR:
zbx_free(value->data.str);
break;
case ZBX_VARIANT_BIN:
zbx_free(value->data.bin);
break;
case ZBX_VARIANT_ERR:
zbx_free(value->data.err);
break;
case ZBX_VARIANT_VECTOR:
if (NULL != value->data.vector)
{
if (0 < value->data.vector->values_num)
zbx_vector_var_clear_ext(value->data.vector);
zbx_vector_var_destroy(value->data.vector);
}
zbx_free(value->data.vector);
break;
case ZBX_VARIANT_NONE:
case ZBX_VARIANT_DBL:
case ZBX_VARIANT_UI64:
break;
default:
THIS_SHOULD_NEVER_HAPPEN;