mirror of https://github.com/getdnsapi/getdns.git
String bindata's secretly contain final '\0'
This commit is contained in:
parent
7b47e82eae
commit
938eef1b00
26
src/dict.c
26
src/dict.c
|
@ -280,8 +280,7 @@ getdns_dict_get_names(const getdns_dict *dict, getdns_list **answer)
|
|||
|
||||
RBTREE_FOR(item, struct getdns_dict_item *,
|
||||
(_getdns_rbtree_t *)&(dict->root)) {
|
||||
_getdns_list_append_const_bindata(*answer,
|
||||
strlen(item->node.key), item->node.key);
|
||||
_getdns_list_append_string(*answer, item->node.key);
|
||||
}
|
||||
return GETDNS_RETURN_GOOD;
|
||||
} /* getdns_dict_get_names */
|
||||
|
@ -657,9 +656,26 @@ getdns_dict_set_bindata(
|
|||
getdns_return_t
|
||||
getdns_dict_util_set_string(getdns_dict *dict, char *name, const char *value)
|
||||
{
|
||||
return value
|
||||
? _getdns_dict_set_const_bindata(dict, name, strlen(value), value)
|
||||
: GETDNS_RETURN_INVALID_PARAMETER;
|
||||
getdns_item *item;
|
||||
getdns_bindata *newbindata;
|
||||
getdns_return_t r;
|
||||
|
||||
if (!dict || !name || !value)
|
||||
return GETDNS_RETURN_INVALID_PARAMETER;
|
||||
|
||||
if (!(newbindata = _getdns_bindata_copy(
|
||||
&dict->mf, strlen(value) + 1, (uint8_t *)value)))
|
||||
return GETDNS_RETURN_MEMORY_ERROR;
|
||||
|
||||
newbindata->size -= 1;
|
||||
|
||||
if ((r = _getdns_dict_find_and_add(dict, name, &item))) {
|
||||
_getdns_bindata_destroy(&dict->mf, newbindata);
|
||||
return r;
|
||||
}
|
||||
item->dtype = t_bindata;
|
||||
item->data.bindata = newbindata;
|
||||
return GETDNS_RETURN_GOOD;
|
||||
} /* getdns_dict_util_set_dict */
|
||||
|
||||
/*---------------------------------------- getdns_dict_set_int */
|
||||
|
|
22
src/list.c
22
src/list.c
|
@ -602,9 +602,25 @@ getdns_list_set_bindata(
|
|||
static getdns_return_t
|
||||
getdns_list_set_string(getdns_list *list, size_t index, const char *value)
|
||||
{
|
||||
return value
|
||||
? _getdns_list_set_const_bindata(list, index, strlen(value), value)
|
||||
: GETDNS_RETURN_INVALID_PARAMETER;
|
||||
getdns_bindata *newbindata;
|
||||
getdns_return_t r;
|
||||
|
||||
if (!list || !value)
|
||||
return GETDNS_RETURN_INVALID_PARAMETER;
|
||||
|
||||
if (!(newbindata = _getdns_bindata_copy(
|
||||
&list->mf, strlen(value) + 1, (uint8_t *)value)))
|
||||
return GETDNS_RETURN_MEMORY_ERROR;
|
||||
|
||||
newbindata->size -= 1;
|
||||
|
||||
if ((r = _getdns_list_request_index(list, index))) {
|
||||
_getdns_bindata_destroy(&list->mf, newbindata);
|
||||
return r;
|
||||
}
|
||||
list->items[index].dtype = t_bindata;
|
||||
list->items[index].data.bindata = newbindata;
|
||||
return GETDNS_RETURN_GOOD;
|
||||
} /* getdns_list_set_string */
|
||||
|
||||
/*---------------------------------------- getdns_list_set_int */
|
||||
|
|
Loading…
Reference in New Issue