introduce LWS_WARN_UNUSED_RESULT
authorAndy Green <andy.green@linaro.org>
Wed, 20 Jan 2016 08:56:06 +0000 (16:56 +0800)
committerAndy Green <andy.green@linaro.org>
Wed, 20 Jan 2016 08:56:06 +0000 (16:56 +0800)
Signed-off-by: Andy Green <andy.green@linaro.org>
lib/client-parser.c
lib/libwebsockets.c
lib/libwebsockets.h
lib/output.c
lib/parsers.c
lib/private-libwebsockets.h
lib/service.c

index 1ae473f..65a40a5 100644 (file)
@@ -389,10 +389,9 @@ spill:
                         * we do not care about how it went, we are closing
                         * immediately afterwards
                         */
-                       lws_write(wsi, (unsigned char *)
-                          &wsi->u.ws.rx_ubuf[
-                               LWS_PRE],
-                               wsi->u.ws.rx_ubuf_head, LWS_WRITE_CLOSE);
+                       lws_write(wsi,
+                                 (unsigned char *)&wsi->u.ws.rx_ubuf[LWS_PRE],
+                                 wsi->u.ws.rx_ubuf_head, LWS_WRITE_CLOSE);
                        wsi->state = LWSS_RETURNED_CLOSE_ALREADY;
                        /* close the connection */
                        return -1;
index 22c8c06..2e1ac8a 100644 (file)
@@ -445,7 +445,8 @@ lws_get_addresses(struct lws_context *context, void *ads, char *name,
        if (addr4.sin_family == AF_UNSPEC)
                return -1;
 
-       lws_plat_inet_ntop(AF_INET, &addr4.sin_addr, rip, rip_len);
+       if (lws_plat_inet_ntop(AF_INET, &addr4.sin_addr, rip, rip_len) == NULL)
+               return -1;
 
        return 0;
 #else
index 09a3164..2ac5f9e 100644 (file)
@@ -150,8 +150,10 @@ extern "C" {
 
 #if defined(__GNUC__)
 #define LWS_VISIBLE __attribute__((visibility("default")))
+#define LWS_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
 #else
 #define LWS_VISIBLE
+#define LWS_WARN_UNUSED_RESULT
 #endif
 
 #if defined(__ANDROID__)
@@ -1418,7 +1420,8 @@ LWS_VISIBLE LWS_EXTERN void
 lws_cancel_service(struct lws_context *context);
 
 LWS_VISIBLE LWS_EXTERN int
-lws_interface_to_sa(int ipv6, const char *ifname, struct sockaddr_in *addr, size_t addrlen);
+lws_interface_to_sa(int ipv6, const char *ifname, struct sockaddr_in *addr,
+                   size_t addrlen);
 
 LWS_VISIBLE LWS_EXTERN const unsigned char *
 lws_token_to_string(enum lws_token_indexes token);
@@ -1650,23 +1653,23 @@ LWS_VISIBLE LWS_EXTERN size_t
 lws_get_peer_write_allowance(struct lws *wsi);
 
 /* deprecated, use lws_client_connect_via_info() */
-LWS_VISIBLE LWS_EXTERN struct lws *
+LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
 lws_client_connect(struct lws_context *clients, const char *address,
                   int port, int ssl_connection, const char *path,
                   const char *host, const char *origin, const char *protocol,
                   int ietf_version_or_minus_one);
 /* deprecated, use lws_client_connect_via_info() */
-LWS_VISIBLE LWS_EXTERN struct lws *
+LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
 lws_client_connect_extended(struct lws_context *clients, const char *address,
                            int port, int ssl_connection, const char *path,
                            const char *host, const char *origin,
                            const char *protocol, int ietf_version_or_minus_one,
                            void *userdata);
 
-LWS_VISIBLE LWS_EXTERN struct lws *
+LWS_VISIBLE LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
 lws_client_connect_via_info(struct lws_client_connect_info * ccinfo);
 
-LWS_VISIBLE LWS_EXTERN const char *
+LWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT
 lws_canonical_hostname(struct lws_context *context);
 
 
@@ -1677,16 +1680,16 @@ lws_get_peer_addresses(struct lws *wsi, lws_sockfd_type fd, char *name,
 LWS_VISIBLE LWS_EXTERN int
 lws_get_random(struct lws_context *context, void *buf, int len);
 
-LWS_VISIBLE LWS_EXTERN int
+LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_daemonize(const char *_lock_path);
 
-LWS_VISIBLE LWS_EXTERN int
+LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_send_pipe_choked(struct lws *wsi);
 
-LWS_VISIBLE LWS_EXTERN int
+LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_partial_buffered(struct lws *wsi);
 
-LWS_VISIBLE LWS_EXTERN int
+LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_frame_is_binary(struct lws *wsi);
 
 LWS_VISIBLE LWS_EXTERN int
@@ -1704,10 +1707,10 @@ lws_b64_encode_string(const char *in, int in_len, char *out, int out_size);
 LWS_VISIBLE LWS_EXTERN int
 lws_b64_decode_string(const char *in, char *out, int out_size);
 
-LWS_VISIBLE LWS_EXTERN const char *
+LWS_VISIBLE LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT
 lws_get_library_version(void);
 
-LWS_VISIBLE LWS_EXTERN int
+LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_parse_uri(char *p, const char **prot, const char **ads, int *port,
              const char **path);
 
@@ -1730,10 +1733,10 @@ lws_parse_uri(char *p, const char **prot, const char **ads, int *port,
  *  will fail with a nonzero return code.
  */
 
-LWS_VISIBLE LWS_EXTERN int
+LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h);
 
-LWS_VISIBLE LWS_EXTERN int
+LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, int frag_idx);
 
 /*
@@ -1745,7 +1748,7 @@ lws_hdr_copy(struct lws *wsi, char *dest, int len, enum lws_token_indexes h);
 
 /*
  * copies only fragment frag_idx of a header.  Normally this is only useful
- * to parse URI arguments like ?x=1&y=2, oken index WSI_TOKEN_HTTP_URI_ARGS
+ * to parse URI arguments like ?x=1&y=2, token index WSI_TOKEN_HTTP_URI_ARGS
  * fragment 0 will contain "x=1" and fragment 1 "y=2"
  */
 LWS_VISIBLE LWS_EXTERN int
@@ -1754,13 +1757,13 @@ lws_hdr_copy_fragment(struct lws *wsi, char *dest, int len,
 
 
 /* get the active file operations struct */
-LWS_VISIBLE LWS_EXTERN struct lws_plat_file_ops *
+LWS_VISIBLE LWS_EXTERN struct lws_plat_file_ops * LWS_WARN_UNUSED_RESULT
 lws_get_fops(struct lws_context *context);
 
-LWS_VISIBLE LWS_EXTERN struct lws_context *
+LWS_VISIBLE LWS_EXTERN struct lws_context * LWS_WARN_UNUSED_RESULT
 lws_get_context(const struct lws *wsi);
 
-LWS_VISIBLE LWS_EXTERN int
+LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_get_count_threads(struct lws_context *context);
 
 /*
@@ -1778,7 +1781,7 @@ lws_get_count_threads(struct lws_context *context);
  * without having to deal with differences between platforms.
  */
 
-static LWS_INLINE lws_filefd_type
+static LWS_INLINE lws_filefd_type LWS_WARN_UNUSED_RESULT
 lws_plat_file_open(struct lws *wsi, const char *filename,
                   unsigned long *filelen, int flags)
 {
@@ -1798,7 +1801,7 @@ lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
        return lws_get_fops(lws_get_context(wsi))->seek_cur(wsi, fd, offset);
 }
 
-static LWS_INLINE int
+static LWS_INLINE int LWS_WARN_UNUSED_RESULT
 lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
                   unsigned char *buf, unsigned long len)
 {
@@ -1806,7 +1809,7 @@ lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
                                                        len);
 }
 
-static LWS_INLINE int
+static LWS_INLINE int LWS_WARN_UNUSED_RESULT
 lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amount,
                    unsigned char *buf, unsigned long len)
 {
@@ -1824,7 +1827,7 @@ lws_read(struct lws *wsi, unsigned char *buf, size_t len);
 #ifndef LWS_NO_EXTENSIONS
 /* deprecated */
 #define lws_get_internal_extensions() NULL
-LWS_VISIBLE LWS_EXTERN int
+LWS_VISIBLE LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_ext_parse_options(const struct lws_extension *ext, struct lws *wsi,
                       void *ext_user, const struct lws_ext_options *opts, const char *o, int len);
 #endif
index 74ff856..86d63d4 100644 (file)
@@ -602,10 +602,11 @@ all_sent:
 
                        if (wsi->protocol->callback)
                                /* ignore callback returned value */
-                               user_callback_handle_rxflow(
-                                       wsi->protocol->callback, wsi,
-                                       LWS_CALLBACK_HTTP_FILE_COMPLETION,
-                                       wsi->user_space, NULL, 0);
+                               if (user_callback_handle_rxflow(
+                                    wsi->protocol->callback, wsi,
+                                    LWS_CALLBACK_HTTP_FILE_COMPLETION,
+                                    wsi->user_space, NULL, 0) < 0)
+                                       return -1;
                        return 1;  /* >0 indicates completed */
                }
        }
index e1fdd24..3d198e1 100644 (file)
@@ -27,7 +27,8 @@ unsigned char lextable[] = {
 
 #define FAIL_CHAR 0x08
 
-int lextable_decode(int pos, char c)
+int
+LWS_WARN_UNUSED_RESULT lextable_decode(int pos, char c)
 {
        if (c >= 'A' && c <= 'Z')
                c += 'a' - 'A';
@@ -59,7 +60,8 @@ int lextable_decode(int pos, char c)
        }
 }
 
-int lws_allocate_header_table(struct lws *wsi)
+int
+LWS_WARN_UNUSED_RESULT lws_allocate_header_table(struct lws *wsi)
 {
        struct lws_context *context = wsi->context;
        int n;
@@ -315,7 +317,8 @@ static signed char char_to_hex(const char c)
        return -1;
 }
 
-static int issue_char(struct lws *wsi, unsigned char c)
+static int LWS_WARN_UNUSED_RESULT
+issue_char(struct lws *wsi, unsigned char c)
 {
        unsigned short frag_len;
 
@@ -350,7 +353,8 @@ static int issue_char(struct lws *wsi, unsigned char c)
        return 1;
 }
 
-int lws_parse(struct lws *wsi, unsigned char c)
+int LWS_WARN_UNUSED_RESULT
+lws_parse(struct lws *wsi, unsigned char c)
 {
        static const unsigned char methods[] = {
                WSI_TOKEN_GET_URI,
@@ -422,7 +426,8 @@ int lws_parse(struct lws *wsi, unsigned char c)
                case URIES_SEEN_PERCENT_H1:
                        if (char_to_hex(c) < 0) {
                                /* regurgitate */
-                               issue_char(wsi, '%');
+                               if (issue_char(wsi, '%') < 0)
+                                       return -1;
                                wsi->u.hdr.ues = URIES_IDLE;
                                /* regurgitate + assess */
                                if (lws_parse(wsi, wsi->u.hdr.esc_stash) < 0)
index 44295b7..b1eb8bc 100644 (file)
@@ -1026,13 +1026,13 @@ lws_latency(struct lws_context *context, struct lws *wsi, const char *action,
 LWS_EXTERN void
 lws_set_protocol_write_pending(struct lws *wsi,
                               enum lws_pending_protocol_send pend);
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_client_rx_sm(struct lws *wsi, unsigned char c);
 
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_parse(struct lws *wsi, unsigned char c);
 
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_http_action(struct lws *wsi);
 
 LWS_EXTERN int
@@ -1053,27 +1053,27 @@ delete_from_fd(struct lws_context *context, lws_sockfd_type fd);
 #define delete_from_fd(A,B) A->lws_lookup[B]=0
 #endif
 
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi);
 
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len);
 
 
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_service_timeout_check(struct lws *wsi, unsigned int sec);
 
-LWS_EXTERN struct lws *
+LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
 lws_client_connect_2(struct lws *wsi);
 
-LWS_VISIBLE struct lws *
-lws_client_reset(struct lws *wsi, int ssl, const char *address, int port, const char *path, const char *host);
+LWS_VISIBLE struct lws * LWS_WARN_UNUSED_RESULT
+lws_client_reset(struct lws *wsi, int ssl, const char *address, int port,
+                const char *path, const char *host);
 
-
-LWS_EXTERN struct lws *
+LWS_EXTERN struct lws * LWS_WARN_UNUSED_RESULT
 lws_create_new_server_wsi(struct lws_context *context);
 
-LWS_EXTERN char *
+LWS_EXTERN char * LWS_WARN_UNUSED_RESULT
 lws_generate_client_handshake(struct lws *wsi, char *pkt);
 
 LWS_EXTERN int
@@ -1088,17 +1088,14 @@ LWS_VISIBLE void
 lws_context_init_extensions(struct lws_context_creation_info *info,
                            struct lws_context *context);
 LWS_EXTERN int
-lws_any_extension_handled(struct lws *wsi,
-                         enum lws_extension_callback_reasons r,
+lws_any_extension_handled(struct lws *wsi, enum lws_extension_callback_reasons r,
                          void *v, size_t len);
 
 LWS_EXTERN int
-lws_ext_cb_active(struct lws *wsi, int reason,
-                                void *buf, int len);
+lws_ext_cb_active(struct lws *wsi, int reason, void *buf, int len);
 LWS_EXTERN int
-lws_ext_cb_all_exts(struct lws_context *context,
-                                        struct lws *wsi, int reason,
-                                        void *arg, int len);
+lws_ext_cb_all_exts(struct lws_context *context, struct lws *wsi, int reason,
+                   void *arg, int len);
 
 #else
 #define lws_any_extension_handled(_a, _b, _c, _d) (0)
@@ -1108,19 +1105,19 @@ lws_ext_cb_all_exts(struct lws_context *context,
 #define lws_context_init_extensions(_a, _b)
 #endif
 
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_client_interpret_server_handshake(struct lws *wsi);
 
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_rx_sm(struct lws *wsi, unsigned char c);
 
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_issue_raw_ext_access(struct lws *wsi, unsigned char *buf, size_t len);
 
 LWS_EXTERN void
 lws_union_transition(struct lws *wsi, enum connection_mode mode);
 
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 user_callback_handle_rxflow(lws_callback_function, struct lws *wsi,
                            enum lws_callback_reasons reason, void *user,
                            void *in, size_t len);
@@ -1165,16 +1162,16 @@ void lws_http2_configure_if_upgraded(struct lws *wsi);
 LWS_EXTERN int
 lws_plat_set_socket_options(struct lws_context *context, lws_sockfd_type fd);
 
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_allocate_header_table(struct lws *wsi);
 
 LWS_EXTERN int
 lws_free_header_table(struct lws *wsi);
 
-LWS_EXTERN char *
+LWS_EXTERN char * LWS_WARN_UNUSED_RESULT
 lws_hdr_simple_ptr(struct lws *wsi, enum lws_token_indexes h);
 
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_hdr_simple_create(struct lws *wsi, enum lws_token_indexes h, const char *s);
 
 LWS_EXTERN int
@@ -1188,7 +1185,7 @@ int lws_context_init_server(struct lws_context_creation_info *info,
                            struct lws_context *context);
 LWS_EXTERN int
 handshake_0405(struct lws_context *context, struct lws *wsi);
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_interpret_incoming_packet(struct lws *wsi, unsigned char **buf, size_t len);
 LWS_EXTERN void
 lws_server_get_canonical_hostname(struct lws_context *context,
@@ -1206,7 +1203,7 @@ LWS_EXTERN int get_daemonize_pid();
 #endif
 
 #if !defined(MBED_OPERATORS)
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 interface_to_sa(struct lws_context *context, const char *ifname,
                struct sockaddr_in *addr, size_t addrlen);
 #endif
@@ -1232,13 +1229,13 @@ enum lws_ssl_capable_status {
 #else
 #define LWS_SSL_ENABLED(context) (context->use_ssl)
 LWS_EXTERN int openssl_websocket_private_data_index;
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len);
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, int len);
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_ssl_pending(struct lws *wsi);
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_server_socket_service_ssl(struct lws **wsi, struct lws *new_wsi,
                              lws_sockfd_type accept_fd,
                              struct lws_pollfd *pollfd);
@@ -1268,13 +1265,13 @@ lws_context_init_http2_ssl(struct lws_context *context);
 #endif
 #endif
 
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_ssl_capable_read_no_ssl(struct lws *wsi, unsigned char *buf, int len);
 
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_ssl_capable_write_no_ssl(struct lws *wsi, unsigned char *buf, int len);
 
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_ssl_pending_no_ssl(struct lws *wsi);
 
 #ifndef LWS_NO_CLIENT
@@ -1288,7 +1285,7 @@ lws_context_init_client_ssl(struct lws_context_creation_info *info,
 #else
        #define lws_context_init_client_ssl(_a, _b) (0)
 #endif
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len);
 LWS_EXTERN void
 lws_decode_ssl_error(void);
@@ -1321,10 +1318,10 @@ lws_get_addresses(struct lws_context *context, void *ads, char *name,
 /*
  * custom allocator
  */
-LWS_EXTERN void*
+LWS_EXTERN void *
 lws_realloc(void *ptr, size_t size);
 
-LWS_EXTERN void*
+LWS_EXTERN void * LWS_WARN_UNUSED_RESULT
 lws_zalloc(size_t size);
 
 #define lws_malloc(S)  lws_realloc(NULL, S)
@@ -1363,10 +1360,10 @@ LWS_EXTERN void
 lws_plat_drop_app_privileges(struct lws_context_creation_info *info);
 LWS_EXTERN unsigned long long
 time_in_microseconds(void);
-LWS_EXTERN const char *
+LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT
 lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt);
 
-LWS_EXTERN int
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
 lws_check_utf8(unsigned char *state, unsigned char *buf, size_t len);
 
 #ifdef __cplusplus
index 8f4f4f6..e17a525 100644 (file)
@@ -390,7 +390,7 @@ lws_service_fd_tsi(struct lws_context *context, struct lws_pollfd *pollfd, int t
        if (context->lserv_fd)
                idx = wsi_from_fd(context, context->lserv_fd)->position_in_fds_table;
 #endif
-         /*
+       /*
         * you can call us with pollfd = NULL to just allow the once-per-second
         * global timeout checks; if less than a second since the last check
         * it returns immediately then.