Thanks to David CARLIER.
p = nxt_malloc(size);
if (p != NULL) {
- memset(p, 0, size);
+ nxt_memzero(p, size);
}
return p;
return NXT_ERROR;
}
- memset(frame, 0, NJS_GLOBAL_FRAME_SIZE);
+ nxt_memzero(frame, NJS_GLOBAL_FRAME_SIZE);
vm->top_frame = &frame->native;
vm->active_frame = frame;
alg->final(digest, &ctx->u);
memcpy(key_buf, digest, alg->size);
- memset(key_buf + alg->size, 0, sizeof(key_buf) - alg->size);
+ nxt_explicit_memzero(key_buf + alg->size, sizeof(key_buf) - alg->size);
} else {
memcpy(key_buf, key.start, key.length);
- memset(key_buf + key.length, 0, sizeof(key_buf) - key.length);
+ nxt_explicit_memzero(key_buf + key.length,
+ sizeof(key_buf) - key.length);
}
for (i = 0; i < 64; i++) {
time = njs_date_string_parse(&args[1]);
} else {
- memset(values, 0, 8 * sizeof(int64_t));
+ nxt_memzero(values, 8 * sizeof(int64_t));
/* Month. */
values[2] = 1;
time = NAN;
if (nargs > 2) {
- memset(values, 0, 8 * sizeof(int32_t));
+ nxt_memzero(values, 8 * sizeof(int32_t));
n = nxt_min(8, nargs);
vm->stack_size += spare_size;
}
- memset(frame, 0, sizeof(njs_native_frame_t));
+ nxt_memzero(frame, sizeof(njs_native_frame_t));
frame->size = chunk_size;
frame->free_size = spare_size - size;
njs_opts_t opts;
njs_vm_opt_t vm_options;
- memset(&opts, 0, sizeof(njs_opts_t));
+ nxt_memzero(&opts, sizeof(njs_opts_t));
opts.interactive = 1;
ret = njs_get_options(&opts, argc, argv);
return EXIT_SUCCESS;
}
- memset(&vm_options, 0, sizeof(njs_vm_opt_t));
+ nxt_memzero(&vm_options, sizeof(njs_vm_opt_t));
vm_options.accumulative = 1;
vm_options.backtrace = 1;
njs_vm_opt_t options;
struct rusage usage;
- memset(&options, 0, sizeof(njs_vm_opt_t));
+ nxt_memzero(&options, sizeof(njs_vm_opt_t));
vm = NULL;
nvm = NULL;
fflush(stdout);
}
- memset(&options, 0, sizeof(njs_vm_opt_t));
+ nxt_memzero(&options, sizeof(njs_vm_opt_t));
options.accumulative = 1;
options.backtrace = 1;
fflush(stdout);
}
- memset(&options, 0, sizeof(njs_vm_opt_t));
+ nxt_memzero(&options, sizeof(njs_vm_opt_t));
vm = njs_vm_create(&options);
if (vm == NULL) {
rc = NXT_ERROR;
vm = NULL;
- memset(&options, 0, sizeof(njs_vm_opt_t));
+ nxt_memzero(&options, sizeof(njs_vm_opt_t));
for (i = 0; i < nxt_nitems(njs_api_test); i++) {
test = &njs_api_test[i];
. ${NXT_AUTO}time
. ${NXT_AUTO}memalign
. ${NXT_AUTO}getrandom
+. ${NXT_AUTO}explicit_bzero
. ${NXT_AUTO}pcre
. ${NXT_AUTO}editline
. ${NXT_AUTO}expect
--- /dev/null
+
+# Copyright (C) Igor Sysoev
+# Copyright (C) NGINX, Inc.
+
+
+# Linux (glibc and musl from 1.1.20), OpenBSD, FreeBSD and NetBSD.
+
+nxt_feature="explicit_bzero()"
+nxt_feature_name=NXT_HAVE_EXPLICIT_BZERO
+nxt_feature_run=yes
+nxt_feature_incs=
+nxt_feature_libs=
+nxt_feature_test="#include <strings.h>
+ #include <string.h>
+
+ int main(void) {
+ int r;
+
+ explicit_bzero(&r, sizeof(r));
+ return 0;
+ }"
+. ${NXT_AUTO}feature
+
+
+if [ $nxt_found = no ]; then
+
+ # NetBSD has explicit_memset instead.
+
+ nxt_feature="explicit_memset()"
+ nxt_feature_name=NXT_HAVE_EXPLICIT_MEMSET
+ nxt_feature_test="#include <string.h>
+
+ int main(void) {
+ int r;
+
+ explicit_memset(&r, 0, sizeof(r));
+ return 0;
+ }"
+ . ${NXT_AUTO}feature
+fi
#include <nxt_clang.h>
#include <nxt_stub.h>
#include <nxt_array.h>
+#include <nxt_string.h>
#include <string.h>
item = nxt_array_add(array, proto, pool);
if (nxt_fast_path(item != NULL)) {
- memset(item, 0, array->item_size);
+ nxt_memzero(item, array->item_size);
}
return item;
return NXT_ERROR;
}
- memset(lvl, 0, size * (sizeof(void *)));
+ nxt_memzero(lvl, size * (sizeof(void *)));
level = lvl;
shift = 0;
#define nxt_lvlhsh_each_init(lhe, _proto) \
do { \
- memset(lhe, 0, sizeof(nxt_lvlhsh_each_t)); \
+ nxt_memzero(lhe, sizeof(nxt_lvlhsh_each_t)); \
(lhe)->proto = _proto; \
} while (0)
#include <nxt_types.h>
#include <nxt_clang.h>
#include <nxt_md5.h>
+#include <nxt_string.h>
#include <string.h>
free = 64 - used;
if (free < 8) {
- memset(&ctx->buffer[used], 0, free);
+ nxt_memzero(&ctx->buffer[used], free);
(void) nxt_md5_body(ctx, ctx->buffer, 64);
used = 0;
free = 64;
}
- memset(&ctx->buffer[used], 0, free - 8);
+ nxt_memzero(&ctx->buffer[used], free - 8);
ctx->bytes <<= 3;
ctx->buffer[56] = (u_char) ctx->bytes;
result[14] = (u_char) (ctx->d >> 16);
result[15] = (u_char) (ctx->d >> 24);
- memset(ctx, 0, sizeof(*ctx));
+ nxt_memzero(ctx, sizeof(*ctx));
}
#include <nxt_clang.h>
#include <nxt_alignment.h>
#include <nxt_stub.h>
+#include <nxt_string.h>
#include <nxt_queue.h>
#include <nxt_rbtree.h>
#include <nxt_mem_cache_pool.h>
p = nxt_mem_cache_alloc(pool, size);
if (nxt_fast_path(p != NULL)) {
- memset(p, 0, size);
+ nxt_memzero(p, size);
}
return p;
p = nxt_mem_cache_align(pool, alignment, size);
if (nxt_fast_path(p != NULL)) {
- memset(p, 0, size);
+ nxt_memzero(p, size);
}
return p;
#include <nxt_types.h>
#include <nxt_clang.h>
#include <nxt_sha1.h>
+#include <nxt_string.h>
#include <string.h>
free = 64 - used;
if (free < 8) {
- memset(&ctx->buffer[used], 0, free);
+ nxt_memzero(&ctx->buffer[used], free);
(void) nxt_sha1_body(ctx, ctx->buffer, 64);
used = 0;
free = 64;
}
- memset(&ctx->buffer[used], 0, free - 8);
+ nxt_memzero(&ctx->buffer[used], free - 8);
ctx->bytes <<= 3;
ctx->buffer[56] = (u_char) (ctx->bytes >> 56);
result[18] = (u_char) (ctx->e >> 8);
result[19] = (u_char) ctx->e;
- memset(ctx, 0, sizeof(*ctx));
+ nxt_memzero(ctx, sizeof(*ctx));
}
#include <nxt_types.h>
#include <nxt_clang.h>
#include <nxt_sha2.h>
+#include <nxt_string.h>
#include <string.h>
free = 64 - used;
if (free < 8) {
- memset(&ctx->buffer[used], 0, free);
+ nxt_memzero(&ctx->buffer[used], free);
(void) nxt_sha2_body(ctx, ctx->buffer, 64);
used = 0;
free = 64;
}
- memset(&ctx->buffer[used], 0, free - 8);
+ nxt_memzero(&ctx->buffer[used], free - 8);
ctx->bytes <<= 3;
ctx->buffer[56] = (u_char) (ctx->bytes >> 56);
result[30] = (u_char) (ctx->h >> 8);
result[31] = (u_char) ctx->h;
- memset(ctx, 0, sizeof(*ctx));
+ nxt_memzero(ctx, sizeof(*ctx));
}
#define nxt_cpymem(dst, src, n) (((u_char *) memcpy(dst, src, n)) + (n))
+#define nxt_memzero(buf, length) (void) (memset(buf, 0, length))
+
+
+#if (NXT_HAVE_EXPLICIT_BZERO)
+#define nxt_explicit_memzero(buf, length) \
+ (void) (explicit_bzero(buf, length))
+#elif (NXT_HAVE_EXPLICIT_MEMSET)
+#define nxt_explicit_memzero(buf, length) \
+ (void) (explicit_memset(buf, 0, length))
+#else
+#define nxt_explicit_memzero(buf, length) \
+ nxt_memzero(buf, length)
+#endif
+
+
#define nxt_strstr_eq(s1, s2) \
(((s1)->length == (s2)->length) \
&& (memcmp((s1)->start, (s2)->start, (s1)->length) == 0))
p = nxt_malloc(size);
if (p != NULL) {
- memset(p, 0, size);
+ nxt_memzero(p, size);
}
return p;
printf("lvlhsh unit test started: %ld items\n", (long) n);
- memset(&lh, 0, sizeof(nxt_lvlhsh_t));
+ nxt_memzero(&lh, sizeof(nxt_lvlhsh_t));
key = 0;
for (i = 0; i < n; i++) {