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

Valentin Bartenev vbart at nginx.com
Thu Nov 10 13:48:28 UTC 2016


details:   http://hg.nginx.org/njs/rev/60c2930eb951
branches:  
changeset: 248:60c2930eb951
user:      Valentin Bartenev <vbart at 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);



More information about the nginx-devel mailing list