buffer is compared with cp, and so needs to be changed to unsigned too.