Skip to content

Tag some char arrays with __attribute__((__nonstring__)) #871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions auto/clang
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,20 @@ njs_feature_test="__attribute__((no_sanitize(\"undefined\"))) int main(void) {
. auto/feature


njs_feature="GCC __attribute__ nonstring"
njs_feature_name=NJS_HAVE_GCC_ATTRIBUTE_NONSTRING
njs_feature_run=no
njs_feature_incs=
njs_feature_libs=
njs_feature_test="int main(void) {
static const char str[3] __attribute__((nonstring)) =
\"ABC\";

return !!str[0];
}"
. auto/feature


njs_feature="Address sanitizer"
njs_feature_name=NJS_HAVE_ADDRESS_SANITIZER
njs_feature_run=no
Expand Down
2 changes: 1 addition & 1 deletion external/qjs_query_string_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ qjs_string_encode(const uint32_t *escape, size_t size, const u_char *src,
u_char *dst)
{
uint8_t byte;
static const u_char hex[16] = "0123456789ABCDEF";
static const u_char hex[16] NJS_NONSTRING = "0123456789ABCDEF";

do {
byte = *src++;
Expand Down
8 changes: 8 additions & 0 deletions src/njs_clang.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ njs_leading_zeros64(uint64_t x)
#endif


#if (NJS_HAVE_GCC_ATTRIBUTE_NONSTRING)
#define NJS_NONSTRING __attribute__((nonstring))

#else
#define NJS_NONSTRING
#endif


#if (NJS_CLANG)
/* Any __asm__ directive disables loop vectorization in GCC and Clang. */
#define njs_pragma_loop_disable_vectorization __asm__("")
Expand Down
4 changes: 2 additions & 2 deletions src/njs_sprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ njs_vsprintf(u_char *buf, u_char *end, const char *fmt, va_list args)
njs_bool_t sign;
njs_sprintf_t spf;

static const u_char hexadecimal[16] = "0123456789abcdef";
static const u_char HEXADECIMAL[16] = "0123456789ABCDEF";
static const u_char hexadecimal[16] NJS_NONSTRING = "0123456789abcdef";
static const u_char HEXADECIMAL[16] NJS_NONSTRING = "0123456789ABCDEF";
static const u_char nan[] = "[nan]";
static const u_char infinity[] = "[infinity]";

Expand Down
2 changes: 1 addition & 1 deletion src/njs_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ njs_encode_hex(njs_str_t *dst, const njs_str_t *src)
size_t i, len;
const u_char *start;

static const u_char hex[16] = "0123456789abcdef";
static const u_char hex[16] NJS_NONSTRING = "0123456789abcdef";

len = src->length;
start = src->start;
Expand Down
2 changes: 1 addition & 1 deletion src/njs_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ njs_string_encode(const uint32_t *escape, size_t size, const u_char *src,
u_char *dst)
{
uint8_t byte;
static const u_char hex[16] = "0123456789ABCDEF";
static const u_char hex[16] NJS_NONSTRING = "0123456789ABCDEF";

do {
byte = *src++;
Expand Down
2 changes: 1 addition & 1 deletion src/qjs_buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2354,7 +2354,7 @@ qjs_hex_encode(JSContext *ctx, const njs_str_t *src, njs_str_t *dst)
size_t i, len;
const u_char *start;

static const u_char hex[16] = "0123456789abcdef";
static const u_char hex[16] NJS_NONSTRING = "0123456789abcdef";

len = src->length;
start = src->start;
Expand Down