Elegant C?


Some people would consider this elegant. Not me. So many lines dedicated to the manual updating of buffer lengths. First and foremost, the style is just error prone and shouting for buffer exploits. Second, it’s just tedious to write and read; AND that tediousness is what makes it error prone. Third, you’re going to have to write quite a few more tests than you would need if you wrote it using a standard C++ container just to test for buffer access errors.

And a stray observation:

uint16_t data_bytes_to_take = in->size;
if (data_bytes_to_take > s2n_record_max_write_payload_size(conn)) {
data_bytes_to_take = s2n_record_max_write_payload_size(conn);

Could easily be shortened to this:

uint16_t data_bytes_to_take = std::min(in->size, s2n_record_max_write_payload_size(conn));

  • Note how there is no mention of OO style or anything.