Welcome! Log In Create A New Profile

Advanced

[njs] Removed misused __attribute__((malloc)).

Valentin Bartenev
November 10, 2016 08:50AM
details: http://hg.nginx.org/njs/rev/60c2930eb951
branches:
changeset: 248:60c2930eb951
user: Valentin Bartenev <vbart@nginx.com>
date: Thu Nov 10 16:47:52 2016 +0300
description:
Removed misused __attribute__((malloc)).

According to the documentation:

| This tells the compiler that a function is malloc-like, i.e., that the
| pointer P returned by the function cannot alias any other pointer valid
| when the function returns, and moreover no pointers to valid objects
| occur in any storage addressed by P.

The njs_string_alloc() allocates a storage for a string and makes the
storage accessible via the passed "value" argument. The function also
returns an intermediate pointer which is used only for string content
initialization and then discarded. Since the pointer is not stored
anywhere after the initialization, GCC with -O or higher optimisation
levels rightfully optimizes out the initialization.

diffstat:

njs/njs_string.h | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)

diffs (13 lines):

diff -r 9f6d26f5f99b -r 60c2930eb951 njs/njs_string.h
--- a/njs/njs_string.h Thu Nov 10 16:19:13 2016 +0300
+++ b/njs/njs_string.h Thu Nov 10 16:47:52 2016 +0300
@@ -112,8 +112,7 @@ njs_string_length(njs_utf8_t utf8, u_cha
njs_ret_t njs_string_new(njs_vm_t *vm, njs_value_t *value, const u_char *start,
uint32_t size, uint32_t length);
u_char *njs_string_alloc(njs_vm_t *vm, njs_value_t *value, uint32_t size,
- uint32_t length)
- NXT_MALLOC_LIKE;
+ uint32_t length);
void njs_string_copy(njs_value_t *dst, njs_value_t *src);
njs_ret_t njs_string_validate(njs_vm_t *vm, njs_string_prop_t *string,
njs_value_t *value);

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[njs] Removed misused __attribute__((malloc)).

Valentin Bartenev 280 November 10, 2016 08:50AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 292
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready