Closed arteymix closed 7 years ago
Basically, it would be about using strncpy
instead of memcpy
.
What about a special function, eg. set_from_string
that crashes if the array is not a string.
s.t.
set_pointer expects fixed-length string, and
set_from_string expects null-terminated string.
The name set_pointer is horrible by the way, we don't set any pointer but we copy the data from the pointer into the internal buffer. 'copy_pointer'? 'dup_pointer'?, 'set_from_pointer'?
I agree and set_from_pointer
sounds best to me. We should rename set_value
as well since we copy it's internal data field.
Maybe a set_from_string
would a nice-to-have as well with get_string
.
We can also handle null-terminated type in general, though I don't see much interest beyond strings.
I wonder whether we should do this there because actually, if you use the pointer API with string, you have to allocate
scalar_size
.