Skip to content
Snippets Groups Projects
Commit 53e371a1 authored by Daniel Salzman's avatar Daniel Salzman
Browse files

Merge branch 'pkt_begin-again' into 'master'

knot_pkt_begin: fix beginning the same section again

The .pos value might get wrong (though I see no usage ATM).

Notes:
- It still returns KNOT_EOK in case of equality; that's due to usage
  in resolver and requirement to special-case KNOT_ANSWER anyway.
- I would personally assert(false) on all internal failures (e.g. EINVAL),
  as immediate abortion seems preferrable when in debug mode, but the
  code around typically doesn't do that, so I left it without assertions.

See merge request !609
parents bd383a45 1691267f
No related branches found
No related tags found
1 merge request!609knot_pkt_begin: fix beginning the same section again
......@@ -483,17 +483,17 @@ uint16_t knot_pkt_qclass(const knot_pkt_t *pkt)
_public_
int knot_pkt_begin(knot_pkt_t *pkt, knot_section_t section_id)
{
if (pkt == NULL) {
if (pkt == NULL || section_id < pkt->current) {
return KNOT_EINVAL;
}
/* Cannot step to lower section. */
assert(section_id >= pkt->current);
pkt->current = section_id;
/* Remember watermark. */
/* Remember watermark but not on repeated calls. */
pkt->sections[section_id].pkt = pkt;
pkt->sections[section_id].pos = pkt->rrset_count;
if (section_id > pkt->current) {
pkt->sections[section_id].pos = pkt->rrset_count;
}
pkt->current = section_id;
return KNOT_EOK;
}
......
......@@ -212,7 +212,7 @@ uint16_t knot_pkt_qclass(const knot_pkt_t *pkt);
*
* \param pkt
* \param section_id
* \return KNOT_EOK
* \return KNOT_EOK or KNOT_EINVAL
*/
int knot_pkt_begin(knot_pkt_t *pkt, knot_section_t section_id);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment