Skip to content

Commit

Permalink
OpenBSD fixes in memset_s implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
worr committed Sep 14, 2016
1 parent 4b1ea08 commit 3655f65
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
11 changes: 11 additions & 0 deletions library/src/memset_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <stdint.h>
#include <stdlib.h>

#ifndef HAVE_EXPLICIT_BZERO
int memset_s(void* v, size_t smax, int c, size_t n) {
if (v == NULL) return EINVAL;
if (smax > SIZE_MAX) return EINVAL;
Expand All @@ -31,6 +32,16 @@ int memset_s(void* v, size_t smax, int c, size_t n) {
volatile unsigned char *p = v;
while (smax-- && n--) *p++ = c;

/* break lto eliding memset_s */
__asm__ __volatile__("" : : "r"(v) : "memory");

return 0;
}
#else
#include <string.h>
int memset_s(void* v, size_t smax, int c, size_t n) {
explicit_bzero(v, n);
return 0;
}
#endif

6 changes: 4 additions & 2 deletions util/src/memset_s.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ int memset_s(void* v, size_t smax, int c, size_t n) {
return 0;
}
#else
int memset_s(void* v, size_smax, int c, size_t n) {
return explicit_bzero(v, n);
#include <string.h>
int memset_s(void* v, size_t smax, int c, size_t n) {
explicit_bzero(v, n);
return 0;
}
#endif

0 comments on commit 3655f65

Please sign in to comment.