Add more packet splitting debug assertions

Having more debug assertions in functions that split packets guarantees
that they work as expected.
This commit is contained in:
Markus Mäkelä
2018-07-20 11:16:39 +03:00
parent d68f20b75b
commit bbe4f42935
3 changed files with 13 additions and 12 deletions

View File

@ -485,6 +485,17 @@ int modutil_send_mysql_err_packet(DCB *dcb,
return dcb->func.write(dcb, buf);
}
// Helper function for debug assertions
static bool only_one_packet(GWBUF* buffer)
{
ss_dassert(buffer);
uint8_t header[4] = {};
gwbuf_copy_data(buffer, 0, MYSQL_HEADER_LEN, header);
size_t packet_len = gw_mysql_get_byte3(header);
size_t buffer_len = gwbuf_length(buffer);
return packet_len + MYSQL_HEADER_LEN == buffer_len;
}
/**
* Return the first packet from a buffer.
*
@ -531,6 +542,7 @@ GWBUF* modutil_get_next_MySQL_packet(GWBUF** p_readbuf)
}
}
ss_dassert(!packet || only_one_packet(packet));
return packet;
}