Avoid zero length memset error

Adding a check on buffer lenght to avoid a __warn_memset_zero_len
warning on GCC 4.8.2.