Browse Source

[multiple] __attribute_nonnull__ now takes params

define __attribute_nonnull__(params) with params to match
recent changes in glibc development (targetting glibc 2.35 in Feb 2022)

x-ref:
  new __attribute_nonnull__(params) conflicts with third-party
  https://sourceware.org/bugzilla/show_bug.cgi?id=28425
master
Glenn Strauss 2 months ago
parent
commit
575665ad88
  1. 2
      src/base64.h
  2. 10
      src/buffer.c
  3. 84
      src/buffer.h
  4. 2
      src/chunk.c
  5. 6
      src/chunk.h
  6. 2
      src/ck.c
  7. 10
      src/ck.h
  8. 4
      src/first.h
  9. 10
      src/http_kv.h
  10. 10
      src/log.c
  11. 2
      src/mod_indexfile.c
  12. 2
      src/mod_magnet_cache.c
  13. 4
      src/mod_magnet_cache.h
  14. 2
      src/server.c

2
src/base64.h

@ -19,7 +19,7 @@ size_t li_base64_enc(char* restrict out, size_t out_length, const unsigned char*
#define li_to_base64(out, out_length, in, in_length, charset) \
li_base64_enc((out), (out_length), (in), (in_length), (charset), 1)
__attribute_nonnull__
__attribute_nonnull__()
__attribute_returns_nonnull__
char* buffer_append_base64_enc(buffer *out, const unsigned char* in, size_t in_length, base64_charset charset, int pad);

10
src/buffer.c

@ -56,7 +56,7 @@ void buffer_move(buffer * restrict b, buffer * restrict src) {
/* make sure buffer is at least "size" big + 1 for '\0'. keep old data */
__attribute_cold__
__attribute_noinline__
__attribute_nonnull__
__attribute_nonnull__()
__attribute_returns_nonnull__
static char* buffer_realloc(buffer * const restrict b, const size_t len) {
#define BUFFER_PIECE_SIZE 64uL /*(must be power-of-2)*/
@ -78,7 +78,7 @@ static char* buffer_realloc(buffer * const restrict b, const size_t len) {
__attribute_cold__
__attribute_noinline__
__attribute_nonnull__
__attribute_nonnull__()
__attribute_returns_nonnull__
static char* buffer_alloc_replace(buffer * const restrict b, const size_t size) {
/*(discard old data so realloc() does not copy)*/
@ -103,7 +103,7 @@ char* buffer_string_prepare_copy(buffer * const b, const size_t size) {
__attribute_cold__
__attribute_noinline__
__attribute_nonnull__
__attribute_nonnull__()
__attribute_returns_nonnull__
static char* buffer_string_prepare_append_resize(buffer * const restrict b, const size_t size) {
if (b->used < 2) { /* buffer_is_blank(b) */
@ -300,7 +300,7 @@ void buffer_append_uint_hex_lc(buffer *b, uintmax_t value) {
}
}
__attribute_nonnull__
__attribute_nonnull__()
__attribute_returns_nonnull__
static char* utostr(char buf[LI_ITOSTRING_LENGTH], uintmax_t val) {
char *cur = buf+LI_ITOSTRING_LENGTH;
@ -313,7 +313,7 @@ static char* utostr(char buf[LI_ITOSTRING_LENGTH], uintmax_t val) {
return cur;
}
__attribute_nonnull__
__attribute_nonnull__()
__attribute_returns_nonnull__
static char* itostr(char buf[LI_ITOSTRING_LENGTH], intmax_t val) {
/* absolute value not defined for INTMAX_MIN, but can take absolute

84
src/buffer.h

@ -33,7 +33,7 @@ __attribute_malloc__
__attribute_returns_nonnull__
buffer* buffer_init(void);
__attribute_nonnull__
__attribute_nonnull__()
__attribute_returns_nonnull__
buffer* buffer_init_buffer(const buffer *src);
@ -43,7 +43,7 @@ buffer* buffer_init_string(const char *str); /* str can be NULL */
void buffer_free(buffer *b); /* b can be NULL */
/* reset b. if NULL != b && NULL != src, move src content to b. reset src. */
__attribute_nonnull__
__attribute_nonnull__()
void buffer_move(buffer * restrict b, buffer * restrict src);
/* make sure buffer is large enough to store a string of given size
@ -51,7 +51,7 @@ void buffer_move(buffer * restrict b, buffer * restrict src);
* sets b to an empty string, and may drop old content.
* @return b->ptr
*/
__attribute_nonnull__
__attribute_nonnull__()
__attribute_returns_nonnull__
char* buffer_string_prepare_copy(buffer *b, size_t size);
@ -61,7 +61,7 @@ char* buffer_string_prepare_copy(buffer *b, size_t size);
* "used" data is preserved; if not empty buffer must contain a
* zero terminated string.
*/
__attribute_nonnull__
__attribute_nonnull__()
__attribute_returns_nonnull__
char* buffer_string_prepare_append(buffer *b, size_t size);
@ -69,7 +69,7 @@ char* buffer_string_prepare_append(buffer *b, size_t size);
* buffer_string_prepare_append() which only ensures space is available)
* returns pointer to which callers should immediately write x bytes
*/
__attribute_nonnull__
__attribute_nonnull__()
__attribute_returns_nonnull__
char* buffer_extend(buffer * const restrict b, size_t x);
@ -78,7 +78,7 @@ char* buffer_extend(buffer * const restrict b, size_t x);
* requires enough space is present for the terminating zero (prepare with the
* same size to be sure).
*/
__attribute_nonnull__
__attribute_nonnull__()
void buffer_commit(buffer *b, size_t size);
/* clear buffer
@ -86,7 +86,7 @@ void buffer_commit(buffer *b, size_t size);
* - unsets used chars but does not modify existing ptr contents
* (b->ptr *is not* set to an empty, '\0'-terminated string "")
*/
__attribute_nonnull__
__attribute_nonnull__()
static inline void buffer_clear(buffer *b);
/* reset buffer
@ -96,14 +96,14 @@ static inline void buffer_clear(buffer *b);
* (b->ptr *is not* set to an empty, '\0'-terminated string "")
* - frees larger buffer (b->size > BUFFER_MAX_REUSE_SIZE)
*/
__attribute_nonnull__
__attribute_nonnull__()
static inline void buffer_reset(buffer *b);
/* free buffer ptr
* - invalidate buffer contents; free ptr; reset ptr, used, size to 0
*/
__attribute_cold__
__attribute_nonnull__
__attribute_nonnull__()
void buffer_free_ptr(buffer *b);
void buffer_copy_string(buffer * restrict b, const char * restrict s);
@ -123,13 +123,13 @@ struct const_iovec {
};
#endif
__attribute_nonnull__
__attribute_nonnull__()
void buffer_append_iovec(buffer * restrict b, const struct const_iovec *iov, size_t n);
#define buffer_append_uint_hex(b,len) buffer_append_uint_hex_lc((b),(len))
__attribute_nonnull__
__attribute_nonnull__()
void buffer_append_uint_hex_lc(buffer *b, uintmax_t len);
__attribute_nonnull__
__attribute_nonnull__()
void buffer_append_int(buffer *b, intmax_t val);
void buffer_append_strftime(buffer * restrict b, const char * restrict format, const struct tm * restrict tm);
@ -137,44 +137,44 @@ void buffer_append_strftime(buffer * restrict b, const char * restrict format, c
/* '-', log_10 (2^bits) = bits * log 2 / log 10 < bits * 0.31, terminating 0 */
#define LI_ITOSTRING_LENGTH (2 + (8 * sizeof(intmax_t) * 31 + 99) / 100)
__attribute_nonnull__
__attribute_nonnull__()
size_t li_itostrn(char *buf, size_t buf_len, intmax_t val);
__attribute_nonnull__
__attribute_nonnull__()
size_t li_utostrn(char *buf, size_t buf_len, uintmax_t val);
/* buf must be (at least) 2*s_len + 1 big. uses lower-case hex letters. */
#define li_tohex(buf,buf_len,s,s_len) li_tohex_lc((buf),(buf_len),(s),(s_len))
__attribute_nonnull__
__attribute_nonnull__()
void li_tohex_lc(char * restrict buf, size_t buf_len, const char * restrict s, size_t s_len);
__attribute_nonnull__
__attribute_nonnull__()
void li_tohex_uc(char * restrict buf, size_t buf_len, const char * restrict s, size_t s_len);
__attribute_nonnull__
__attribute_nonnull__()
__attribute_pure__
int buffer_eq_icase_ssn(const char * const a, const char * const b, const size_t len);
__attribute_nonnull__
__attribute_nonnull__()
__attribute_pure__
int buffer_eq_icase_ss(const char * const a, const size_t alen, const char * const b, const size_t blen);
__attribute_nonnull__
__attribute_nonnull__()
__attribute_pure__
int buffer_eq_icase_slen(const buffer * const b, const char * const s, const size_t slen);
__attribute_nonnull__
__attribute_nonnull__()
__attribute_pure__
int buffer_eq_slen(const buffer * const b, const char * const s, const size_t slen);
__attribute_nonnull__
__attribute_nonnull__()
__attribute_pure__
int buffer_is_equal(const buffer *a, const buffer *b);
__attribute_nonnull__
__attribute_nonnull__()
void buffer_substr_replace (buffer * restrict b, size_t offset, size_t len, const buffer * restrict replace);
__attribute_nonnull__
__attribute_nonnull__()
void buffer_append_string_encoded_hex_lc(buffer * restrict b, const char * restrict s, size_t len);
__attribute_nonnull__
__attribute_nonnull__()
void buffer_append_string_encoded_hex_uc(buffer * restrict b, const char * restrict s, size_t len);
typedef enum {
@ -187,22 +187,22 @@ typedef enum {
void buffer_append_string_encoded(buffer * restrict b, const char * restrict s, size_t s_len, buffer_encoding_t encoding);
/* escape non-printable characters; simple escapes for \t, \r, \n; fallback to \xCC */
__attribute_nonnull__
__attribute_nonnull__()
void buffer_append_string_c_escaped(buffer * restrict b, const char * restrict s, size_t s_len);
__attribute_nonnull__
__attribute_nonnull__()
void buffer_urldecode_path(buffer *b);
__attribute_nonnull__
__attribute_nonnull__()
__attribute_pure__
int buffer_is_valid_UTF8(const buffer *b);
__attribute_nonnull__
__attribute_nonnull__()
void buffer_path_simplify(buffer *b);
__attribute_nonnull__
__attribute_nonnull__()
void buffer_to_lower(buffer *b);
__attribute_nonnull__
__attribute_nonnull__()
void buffer_to_upper(buffer *b);
@ -248,11 +248,11 @@ static inline int light_isalnum(int c) {
void buffer_append_path_len(buffer * restrict b, const char * restrict a, size_t alen); /* join strings with '/', if '/' not present */
void buffer_copy_path_len2(buffer * restrict b, const char * restrict s1, size_t len1, const char * restrict s2, size_t len2);
__attribute_nonnull__
__attribute_nonnull__()
__attribute_pure__
static inline int buffer_has_slash_suffix (const buffer * const b);
__attribute_nonnull__
__attribute_nonnull__()
__attribute_pure__
static inline int buffer_has_pathsep_suffix (const buffer * const b);
@ -265,14 +265,14 @@ static inline int buffer_has_pathsep_suffix (const buffer * const b);
/* inline implementations */
__attribute_nonnull__
__attribute_nonnull__()
__attribute_pure__
static inline int buffer_is_unset(const buffer *b);
static inline int buffer_is_unset(const buffer *b) {
return 0 == b->used;
}
__attribute_nonnull__
__attribute_nonnull__()
__attribute_pure__
static inline int buffer_is_blank(const buffer *b);
static inline int buffer_is_blank(const buffer *b) {
@ -280,7 +280,7 @@ static inline int buffer_is_blank(const buffer *b) {
}
/* buffer "C" len (bytes) */
__attribute_nonnull__
__attribute_nonnull__()
__attribute_pure__
static inline uint32_t buffer_clen (const buffer *b);
static inline uint32_t buffer_clen (const buffer *b) {
@ -288,40 +288,40 @@ static inline uint32_t buffer_clen (const buffer *b) {
}
/* buffer space remaining to append string without reallocating */
__attribute_nonnull__
__attribute_nonnull__()
__attribute_pure__
static inline uint32_t buffer_string_space(const buffer *b);
static inline uint32_t buffer_string_space(const buffer *b) {
return b->size ? b->size - (b->used | (0 == b->used)) : 0;
}
__attribute_nonnull__
__attribute_nonnull__()
static inline void buffer_copy_buffer(buffer * restrict b, const buffer * restrict src);
static inline void buffer_copy_buffer(buffer * restrict b, const buffer * restrict src) {
buffer_copy_string_len(b, BUF_PTR_LEN(src));
}
__attribute_nonnull__
__attribute_nonnull__()
static inline void buffer_append_buffer(buffer * restrict b, const buffer * restrict src);
static inline void buffer_append_buffer(buffer * restrict b, const buffer * restrict src) {
buffer_append_string_len(b, BUF_PTR_LEN(src));
}
__attribute_nonnull__
__attribute_nonnull__()
static inline void buffer_truncate(buffer *b, uint32_t len);
static inline void buffer_truncate(buffer *b, uint32_t len) {
b->ptr[len] = '\0'; /* b->ptr must exist; use buffer_blank() for trunc 0 */
b->used = len + 1;
}
__attribute_nonnull__
__attribute_nonnull__()
static inline void buffer_blank(buffer *b);
static inline void buffer_blank(buffer *b) {
b->ptr ? buffer_truncate(b, 0) : (void)buffer_extend(b, 0);
}
/* append '/' to non-empty strings not ending in '/' */
__attribute_nonnull__
__attribute_nonnull__()
static inline void buffer_append_slash(buffer *b);
static inline void buffer_append_slash(buffer *b) {
const uint32_t len = buffer_clen(b);
@ -391,7 +391,7 @@ static inline uint32_t buffer_string_length(const buffer *b) {
* - does not modify the string data apart from terminating zero
* - reallocates the buffer iff needed
*/
__attribute_nonnull__
__attribute_nonnull__()
static inline void buffer_string_set_length(buffer *b, uint32_t len);
static inline void buffer_string_set_length(buffer *b, uint32_t len) {
if (len < b->size)

2
src/chunk.c

@ -371,7 +371,7 @@ static chunk * chunkqueue_append_mem_chunk(chunkqueue *cq, size_t sz) {
return c;
}
__attribute_nonnull__
__attribute_nonnull__()
__attribute_returns_nonnull__
static chunk * chunkqueue_append_file_chunk(chunkqueue * const restrict cq, const buffer * const restrict fn, off_t offset, off_t len) {
chunk * const c = chunk_acquire_filechunk();

6
src/chunk.h

@ -60,7 +60,7 @@ buffer * chunk_buffer_acquire(void);
void chunk_buffer_release(buffer *b);
__attribute_nonnull__
__attribute_nonnull__()
void chunk_buffer_yield(buffer *b);
size_t chunk_buffer_prepare_append (buffer *b, size_t sz);
@ -87,10 +87,10 @@ void chunkqueue_append_file_fd(chunkqueue * restrict cq, const buffer * restrict
void chunkqueue_append_mem(chunkqueue * restrict cq, const char * restrict mem, size_t len); /* copies memory */
void chunkqueue_append_mem_min(chunkqueue * restrict cq, const char * restrict mem, size_t len); /* copies memory */
__attribute_nonnull__
__attribute_nonnull__()
void chunkqueue_append_buffer(chunkqueue * restrict cq, buffer * restrict mem); /* may reset "mem" */
__attribute_nonnull__
__attribute_nonnull__()
void chunkqueue_append_chunkqueue(chunkqueue * restrict cq, chunkqueue * restrict src);
__attribute_returns_nonnull__

2
src/ck.c

@ -379,7 +379,7 @@ error:
__attribute_noinline__
__attribute_nonnull__
__attribute_nonnull__()
static void
ck_bt_stderr (const char *filename, unsigned int line, const char *msg, const char *fmt)
{

10
src/ck.h

@ -50,26 +50,26 @@ errno_t ck_strerror_s (char *s, rsize_t maxsize, errno_t errnum);
* constant time memory compare for equality
* rounds to next multiple of 64 to avoid potentially leaking exact
* string lengths when subject to high precision timing attacks */
__attribute_nonnull__
__attribute_nonnull__()
int ck_memeq_const_time (const void *a, size_t alen, const void *b, size_t blen);
/*(ck_memeq_const_time_fixed_len() is not from C11 Annex K)
* constant time memory compare for equality for fixed len (e.g. digests)
* (padding not necessary for digests, which have fixed, defined lengths) */
__attribute_nonnull__
__attribute_nonnull__()
int ck_memeq_const_time_fixed_len (const void *a, const void *b, size_t len);
/*(ck_bt() is not from C11 Annex K)
* ck_bt() prints backtrace to stderr */
__attribute_cold__
__attribute_nonnull__
__attribute_nonnull__()
void ck_bt(const char *filename, unsigned int line, const char *msg);
/*(ck_bt_abort() is not from C11 Annex K)
* ck_bt_abort() prints backtrace to stderr and calls abort() */
__attribute_cold__
__attribute_nonnull__
__attribute_nonnull__()
__attribute_noreturn__
void ck_bt_abort(const char *filename, unsigned int line, const char *msg);
@ -78,7 +78,7 @@ void ck_bt_abort(const char *filename, unsigned int line, const char *msg);
* ck_assert() *is not* optimized away if defined(NDEBUG)
* (unlike standard assert(), which *is* optimized away if defined(NDEBUG)) */
__attribute_cold__
__attribute_nonnull__
__attribute_nonnull__()
__attribute_noreturn__
void ck_assert_failed(const char *filename, unsigned int line, const char *msg);

4
src/first.h

@ -246,9 +246,9 @@ typedef struct unix_timespec64 unix_timespec64_t;
#ifndef __attribute_nonnull__
#if __has_attribute(nonnull) \
|| __GNUC_PREREQ(3,3)
#define __attribute_nonnull__ __attribute__((__nonnull__))
#define __attribute_nonnull__(params) __attribute__((__nonnull__ params))
#else
#define __attribute_nonnull__
#define __attribute_nonnull__(params)
#endif
#endif

10
src/http_kv.h

@ -71,7 +71,7 @@ const char *get_http_version_name(int i);
#define get_http_method_name(i) http_method_buf(i)->ptr
#if 0 /*(unused)*/
__attribute_nonnull__
__attribute_nonnull__()
__attribute_pure__
int get_http_version_key(const char *s, size_t slen);
#endif
@ -79,20 +79,20 @@ int get_http_version_key(const char *s, size_t slen);
__attribute_pure__
const buffer *http_method_buf (http_method_t i);
__attribute_nonnull__
__attribute_nonnull__()
__attribute_pure__
http_method_t get_http_method_key(const char *s, size_t slen);
__attribute_nonnull__
__attribute_nonnull__()
void http_status_append(buffer *b, int status);
__attribute_nonnull__
__attribute_nonnull__()
void http_version_append(buffer *b, http_version_t version);
#define http_method_get_or_head(method) ((method) <= HTTP_METHOD_HEAD)
#define http_method_get_head_post(method) ((method) <= HTTP_METHOD_POST)
__attribute_nonnull__
__attribute_nonnull__()
static inline void http_method_append (buffer * const b, const http_method_t method);
static inline void http_method_append (buffer * const b, const http_method_t method) {
const buffer * const kv = http_method_buf(method);

10
src/log.c

@ -95,7 +95,7 @@ ssize_t write_all(int fd, const void * const buf, size_t count) {
}
__attribute_nonnull__
__attribute_nonnull__()
static void
log_buffer_timestamp (buffer * const restrict b)
{
@ -136,7 +136,7 @@ log_buffer_timestamp (buffer * const restrict b)
}
__attribute_nonnull__
__attribute_nonnull__()
static void
log_buffer_prefix (buffer * const restrict b,
const char * const restrict filename,
@ -168,7 +168,7 @@ log_buffer_append_encoded (buffer * const b,
__attribute_format__((__printf__, 2, 0))
__attribute_nonnull__
__attribute_nonnull__()
static void
log_buffer_vsprintf (buffer * const restrict b,
const char * const restrict fmt, va_list ap)
@ -207,7 +207,7 @@ log_buffer_vsprintf (buffer * const restrict b,
}
__attribute_nonnull__
__attribute_nonnull__()
static buffer *
log_buffer_prepare (const log_error_st * const errh,
const char * const restrict filename,
@ -224,7 +224,7 @@ log_buffer_prepare (const log_error_st * const errh,
}
__attribute_nonnull__
__attribute_nonnull__()
static void
log_error_write (const log_error_st * const errh, buffer * const restrict b)
{

2
src/mod_indexfile.c

@ -78,7 +78,7 @@ SETDEFAULTS_FUNC(mod_indexfile_set_defaults) {
return HANDLER_GO_ON;
}
__attribute_nonnull__
__attribute_nonnull__()
static handler_t mod_indexfile_tryfiles(request_st * const r, const array * const indexfiles) {
for (uint32_t k = 0; k < indexfiles->used; ++k) {
const buffer * const v = &((data_string *)indexfiles->data[k])->value;

2
src/mod_magnet_cache.c

@ -91,7 +91,7 @@ static lua_State *script_cache_load_script(script * const sc, int etag_flags)
}
__attribute_cold__
__attribute_nonnull__
__attribute_nonnull__()
__attribute_returns_nonnull__
static script *script_cache_new_script(script_cache * const cache, const buffer * const name)
{

4
src/mod_magnet_cache.h

@ -31,11 +31,11 @@ __attribute_cold__
void script_cache_free_data(script_cache *cache);
__attribute_cold__
__attribute_nonnull__
__attribute_nonnull__()
__attribute_returns_nonnull__
script *script_cache_get_script(script_cache *cache, const buffer *name);
__attribute_nonnull__
__attribute_nonnull__()
lua_State *script_cache_check_script(script * const sc, int etag_flags);
#endif

2
src/server.c

@ -1910,7 +1910,7 @@ static void server_handle_sigchld (server * const srv) {
}
__attribute_hot__
__attribute_nonnull__
__attribute_nonnull__()
static void server_run_con_queue (connection * const restrict joblist, const connection * const sentinel) {
for (connection *con = joblist, *jqnext; con != sentinel; con = jqnext) {
jqnext = con->jqnext;

Loading…
Cancel
Save