Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
_kst_
on June 1, 2015
|
parent
|
context
|
favorite
| on:
Strncpy() is not a “safer” strcpy()
dest[0] = '\0'; strncat(dest, src, size);
jjnoakes
on June 1, 2015
[–]
Sure. Or:
strncpy(dest, src, size); dest[size - 1] = '\0';
nitrogen
on June 2, 2015
|
parent
[–]
The fact that strncpy zeros the buffer may make it slower.
jjnoakes
on June 2, 2015
|
root
|
parent
[–]
Sure, by a couple of cycles. Unless your size is huge. In which case, perhaps you should try to avoid copying strings in the first place.
Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search: