The problem here is that C-strings are null-terminated.
Instead of using a length, many C functions just read the memory until one of the bytes is '\x00' and take that as the end of the string.
Zig provides functions for that kind of stuff. You can for example use allocator.dupeZ which returns a [:0] u8.
Note that you also need to store it as [:0]u8 or [:0]const u8. If you don’t do it then functions like allocator.free will not know that there is an extra byte in the allocation, and freeing the memory will cause undefined behavior.
You can then extract the raw pointer like this:
const c_str: [*:0]const u8 = item.name.ptr;
Note that I used [*:0]const u8 here because it adds more type-safety than [*c]const u8(which can basically mean anything).