Skip to content

use memcpy() rather than strncpy()#87

Open
alandekok wants to merge 1 commit intomity:masterfrom
alandekok:master
Open

use memcpy() rather than strncpy()#87
alandekok wants to merge 1 commit intomity:masterfrom
alandekok:master

Conversation

@alandekok
Copy link
Copy Markdown

Some projects ban the use of strncpy(), as its' API is not safe. The use of strncpy() here is safe, but is not necessary.

Moving to memcpy() allows acutest to be used in projects which set build flags / macros / etc. that ban the use of insecure functions

The code already:

  • uses "len" to check for overflow,
  • manually zero-terminates the "auxbuf" buffer.
  • calculates "len" as the difference of two pointers

As a result, switching to memcpy() is safe. It's also faster, (for what that's worth) as strncpy() will check for zeros. Since we already used strlen() to bound the copying, the zero checks in strncpy() are not needed.

the rest of the code already:

* uses "len" to check for overflow,
* manually zero-terminates the "auxbuf" buffer.
* calculates "len" as the difference of two pointers

As a result, switching to memcpy() is safe.  It's also faster,
(for what that's worth) as strncpy() will check for zeros.  Since
we already used strlen() to bound the copying, the zero checks in
strncpy() are not needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants