You can use snprintf to limit the amount of buffer used.
function(char* txt, size_t length) { int rv; rv = snprintf(txt, length, "select * from %s;", table); //How do I set last char in buffer to NULL here? if (rv >= length) { // error } }
source share