c
size_t total_size = ...; // Total allocated size of *pData
if (wpos + bplen > total_size) {
    total_size = wpos + bplen;
    BYTE* new_data = realloc(*pData, total_size);
    if (!new_data) goto fail;
    *pData = new_data;
}
memcpy(&(*pData)[wpos], bptr, bplen);
