From a27dfb2a3eadb85f35327fc071321adf4bdd476e Mon Sep 17 00:00:00 2001
From: Andy Green <andy@warmcat.com>
Date: Thu, 23 Aug 2018 11:48:17 +0800
Subject: [PATCH] clean: coverity

---
 lib/core/output.c              | 2 +-
 lib/roles/h2/ops-h2.c          | 5 ++++-
 lib/roles/http/server/server.c | 2 +-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/core/output.c b/lib/core/output.c
index 8f6349bc..af9a53cf 100644
--- a/lib/core/output.c
+++ b/lib/core/output.c
@@ -84,7 +84,7 @@ int lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len)
 		lwsl_debug("%s: draining %d\n", __func__, (int)len);
 	}
 
-	if (!len)
+	if (!len || !buf)
 		return 0;
 
 	if (!wsi->http2_substream && !lws_socket_is_valid(wsi->desc.sockfd))
diff --git a/lib/roles/h2/ops-h2.c b/lib/roles/h2/ops-h2.c
index 636e8f9b..c92dd463 100644
--- a/lib/roles/h2/ops-h2.c
+++ b/lib/roles/h2/ops-h2.c
@@ -362,6 +362,9 @@ rops_write_role_protocol_h2(struct lws *wsi, unsigned char *buf, size_t len,
 	unsigned char flags = 0, base = (*wp) & 0x1f;
 	size_t olen = len;
 	int n;
+#if defined(LWS_WITH_HTTP_STREAM_COMPRESSION)
+	unsigned char mtubuf[1450 + LWS_PRE];
+#endif
 
 	/* if not in a state to send stuff, then just send nothing */
 
@@ -386,7 +389,7 @@ rops_write_role_protocol_h2(struct lws *wsi, unsigned char *buf, size_t len,
 
 #if defined(LWS_WITH_HTTP_STREAM_COMPRESSION)
 	if (wsi->http.lcs) {
-		unsigned char mtubuf[1450 + LWS_PRE], *out = mtubuf + LWS_PRE;
+		unsigned char *out = mtubuf + LWS_PRE;
 		size_t o = sizeof(mtubuf) - LWS_PRE;
 
 		n = lws_http_compression_transform(wsi, buf, len, wp, &out, &o);
diff --git a/lib/roles/http/server/server.c b/lib/roles/http/server/server.c
index e1e1bd97..25751964 100644
--- a/lib/roles/http/server/server.c
+++ b/lib/roles/http/server/server.c
@@ -587,7 +587,7 @@ lws_http_serve(struct lws *wsi, char *uri, const char *origin,
 
 			/* but we still need to send cache control... */
 
-			if (m && m->cache_max_age && m->cache_reusable) {
+			if (m->cache_max_age && m->cache_reusable) {
 				if (!m->cache_revalidate) {
 					cc = cache_control;
 					cclen = sprintf(cache_control, "%s, max-age=%u",
-- 
GitLab