1. malloc() may fail, so you may better check its return value against NULL (or std::nullptr).
2. size may be negative, so better do declare it unsigned.
3. If programming for reliable system you may want to test vp1 and vp2 against NULL.
4. Your function isn't type save. Better use templates to assert the same data type for vp1, vp2 and buffer.
5. Think about defining more reliable data structures, which manage their attributes in a consistent way and protect them against uncontrolled access, like f.e. std::string.
Thank you for you input. The series (video lectures) is getting into how low level memory works and we are just starting to create "generic functions" in place of using templates to heighten our understanding of how programs work in memory.