Messages in this thread | | | From | Ajay Garg <> | Date | Mon, 8 Nov 2021 13:12:37 +0530 | Subject | Re: RFC for a new string-copy function, using mixtures of strlcpy and strscpy |
| |
>> >> The output is as follows : >> >> ###################################################### >> Using [strlcpy] :: >> >> len = [16] >> a = [123456789] >> >> >> Using [strscpy] :: >> >> len = [-7] >> a = [123456789] >> > > My gosh, this is error code that you must check. We do not need more string copy functions. > >
Hmm, having the additional function would make things a lot easier.
For example, in file fs/kernfs/dir.c, there are methods like "kernfs_name_locked", "kernfs_path_from_node_locked" which simply consume the return-value without any checks.
All the above functions have a simple motive : copy as much bytes as possible in the destination buffer, and then consume/return the number of bytes actually copied (minus the null-terminator byte of course).
If checks are to be put in-place, it would be too much code/churn, adding if checks all over the place. If, instead we do a simple replace of "strlcpy" with "strlscpy" at these places, we would be good to go (while *really* meeting the requirements of these clients at the same time).
Anyhow, may be we can wait for some more opinions.
| |