[Info-vax] C str calls

Simon Clubley clubley at remove_me.eisner.decus.org-Earth.UFP
Sat Aug 22 15:45:43 EDT 2015


On 2015-08-22, JF Mezei <jfmezei.spamnot at vaxination.ca> wrote:
> On 15-08-22 13:13, Simon Clubley wrote:
>
>> strncpy() only stops you from walking off into never-never land while
>> processing the source argument.
>
>
> mystring[sizeof(mystring)-1] = 0x00 ; following strncpy fixes the issue
> by null terminating the string no matter what.
>

Various variants of that follow _every_ single usage of strncpy()
in my code.

> personnally, I think memcpy is safer than snrncpy because it makes it
> obvious that the copy operation does not null terminate the string,
> which must be done separately (or string handled as a descriptor type
> with length stored elsewhere)
>

Actually, what would be safer is if C wasn't the dominant language
in use as an architecture neutral low level system implementation
language today...

Simon.

-- 
Simon Clubley, clubley at remove_me.eisner.decus.org-Earth.UFP
Microsoft: Bringing you 1980s technology to a 21st century world



More information about the Info-vax mailing list