about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJosh Rickmar <jrick@conformal.com>2013-06-17 08:53:29 -0400
committerJosh Rickmar <jrick@conformal.com>2013-06-20 10:11:57 -0400
commit1605485841134cbe8048492237257f53947ac8f6 (patch)
treeb17891d8a7cbd91125b49b7b7b8450fab6df77e1
parentd45b6ceced65e0bc4ba688925903152203348bd9 (diff)
downloadxombrero-1605485841134cbe8048492237257f53947ac8f6.tar.gz
Many errors fixed, found by clang static analyzer.
-rw-r--r--about.c36
-rw-r--r--externaleditor.c1
-rw-r--r--tldlist.c2
-rw-r--r--xombrero.c36
4 files changed, 46 insertions, 29 deletions
diff --git a/about.c b/about.c
index fd4c1c0..b609567 100644
--- a/about.c
+++ b/about.c
@@ -715,9 +715,15 @@ add_favorite(struct tab *t, struct karg *args)
 	urilen = strlen(uri);
 
 	for (;;) {
-		if ((line = fparseln(f, &linelen, NULL, NULL, 0)) == NULL)
-			if (feof(f) || ferror(f))
+		if ((line = fparseln(f, &linelen, NULL, NULL, 0)) == NULL) {
+			if (feof(f))
 				break;
+			else {
+				show_oops(t, "Error reading favorites file: %s",
+				    strerror(errno));
+				goto done;
+			}
+		}
 
 		if (linelen == urilen && !strcmp(line, uri))
 			goto done;
@@ -1019,8 +1025,11 @@ generate_xtp_session_key(char **key)
 {
 	uint8_t			rand_bytes[XT_XTP_SES_KEY_SZ];
 
+	if (key == NULL)
+		return;
+
 	/* free old key */
-	if (*key)
+	if (*key != NULL)
 		g_free(*key);
 
 	/* make a new one */
@@ -1079,8 +1088,6 @@ parse_xtp_url(struct tab *t, const char *uri_str)
 		goto clean;
 	if (uri->host == NULL || strlen(uri->host) == 0)
 		goto clean;
-	else
-		class = atoi(uri->host);
 	if ((sv = g_strsplit(uri->path + 1, "/", 3)) == NULL)
 		goto clean;
 
@@ -1222,8 +1229,10 @@ xtp_page_ab(struct tab *t, struct karg *args)
 {
 	char			*page, *body;
 
-	if (t == NULL)
+	if (t == NULL) {
 		show_oops(NULL, "about invalid parameters");
+		return (-1);
+	}
 
 	generate_xtp_session_key(&t->session_key);
 
@@ -1266,7 +1275,7 @@ xtp_page_ab(struct tab *t, struct karg *args)
 	    ,pwd->pw_dir,
 	    XT_XTP_STR,
 	    XT_XTP_AB,
-	    t->session_key,
+	    t->session_key ? t->session_key : "",
 	    XT_XTP_AB_EDIT_CONF,
 	    XT_CONF_FILE
 	    );
@@ -1295,8 +1304,10 @@ xtp_page_fl(struct tab *t, struct karg *args)
 
 	DNPRINTF(XT_D_FAVORITE, "%s:", __func__);
 
-	if (t == NULL)
-		warn("%s: bad param", __func__);
+	if (t == NULL) {
+		show_oops(NULL, "%s: bad param", __func__);
+		return (-1);
+	}
 
 	generate_xtp_session_key(&t->session_key);
 
@@ -1341,7 +1352,8 @@ xtp_page_fl(struct tab *t, struct karg *args)
 			    "<a href='%s%d/%s/%d/%d'>X</a></td>"
 			    "</tr>\n",
 			    body, i, uri, title,
-			    XT_XTP_STR, XT_XTP_FL, t->session_key,
+			    XT_XTP_STR, XT_XTP_FL,
+			    t->session_key ? t->session_key : "",
 			    XT_XTP_FL_REMOVE, i);
 		else
 			body = g_strdup_printf("%s<tr>"
@@ -1842,8 +1854,10 @@ xtp_page_sv(struct tab *t, struct karg *args)
 	struct secviolation	find, *sv;
 	char			*page, *body;
 
-	if (t == NULL)
+	if (t == NULL) {
 		show_oops(NULL, "secviolation invalid parameters");
+		return (-1);
+	}
 
 	generate_xtp_session_key(&t->session_key);
 
diff --git a/externaleditor.c b/externaleditor.c
index ec56b7e..776f8fd 100644
--- a/externaleditor.c
+++ b/externaleditor.c
@@ -73,7 +73,6 @@ update_contents(struct external_editor_args *args)
 				break;
 		}
 		close(fd);
-		fd = -1;
 
 		DPRINTF("external_editor_cb: contents updated\n");
 		if (args->callback)
diff --git a/tldlist.c b/tldlist.c
index b29e955..4b6ea93 100644
--- a/tldlist.c
+++ b/tldlist.c
@@ -435,7 +435,7 @@ tld_get_suffix(const char *domain)
 	 */
 	if (!suffix) {
 		saveptr = NULL;
-		lbl = strrchr2(domain, &saveptr, '.');
+		strrchr2(domain, &saveptr, '.');
 		lbl = strrchr2(domain, &saveptr, '.');
 		suffix = lbl;
 	}
diff --git a/xombrero.c b/xombrero.c
index 55dae05..350b762 100644
--- a/xombrero.c
+++ b/xombrero.c
@@ -885,8 +885,10 @@ load_uri(struct tab *t, const gchar *uri)
 	set_normal_tab_meaning(t);
 
 	if (valid_url_type(uri)) {
-		newuri = guess_url_type(uri);
-		uri = newuri;
+		if ((newuri = guess_url_type(uri)) != NULL)
+			uri = newuri;
+		else
+			uri = "";
 	}
 
 	/* clear :cert show host */
@@ -1708,17 +1710,15 @@ save_certs(struct tab *t, gnutls_x509_crt_t *certs,
 		 * needed.
 		 */
 		cert_buf_sz = 0;
-		rv = gnutls_x509_crt_export(certs[i], GNUTLS_X509_FMT_PEM,
-		    cert_buf, &cert_buf_sz);
-		if (rv == GNUTLS_E_SHORT_MEMORY_BUFFER) {
-			cert_buf = gnutls_malloc(cert_buf_sz * sizeof(char));
-			if (cert_buf == NULL) {
-				show_oops(t, "gnutls_x509_crt_export failed");
-				goto done;
-			}
-			rv = gnutls_x509_crt_export(certs[i],
-			    GNUTLS_X509_FMT_PEM, cert_buf, &cert_buf_sz);
+		gnutls_x509_crt_export(certs[i], GNUTLS_X509_FMT_PEM,
+		    NULL, &cert_buf_sz);
+		cert_buf = gnutls_malloc(cert_buf_sz * sizeof(char));
+		if (cert_buf == NULL) {
+			show_oops(t, "gnutls_x509_crt_export failed");
+			goto done;
 		}
+		rv = gnutls_x509_crt_export(certs[i],
+		    GNUTLS_X509_FMT_PEM, cert_buf, &cert_buf_sz);
 		if (rv != 0) {
 			show_oops(t, "gnutls_x509_crt_export failure: %s",
 			    gnutls_strerror(rv));
@@ -5291,14 +5291,15 @@ download_start(struct tab *t, struct download *d, int flag)
 int
 download_ask_cb(struct tab *t, GdkEventKey *e, gpointer data)
 {
-	struct download *d = data;
+	struct download		*d = data;
 
 	/* unset mode */
 	t->mode_cb = NULL;
 	t->mode_cb_data = NULL;
 
-	if (!e || !d) {
-		e->keyval = GDK_Escape;
+	if (d == NULL) {
+		if (e != NULL)
+			e->keyval = GDK_Escape;
 		return (XT_CB_PASSTHROUGH);
 	}
 
@@ -6135,6 +6136,9 @@ cmd_getlist(int id, char *key)
 	struct history		*h;
 	struct session		*s;
 
+	if (key == NULL)
+		return;
+
 	if (id >= 0) {
 		if (cmds[id].type & XT_URLARG) {
 			RB_FOREACH_REVERSE(h, history_list, &hl)
@@ -6218,7 +6222,7 @@ cmd_complete(struct tab *t, char *str, int dir)
 	int			i, j, levels, c = 0, dep = 0, parent = -1;
 	int			matchcount = 0;
 	char			*tok, *match, *s = g_strdup(str);
-	char			*tokens[3];
+	char			*tokens[3] = {'\0'};
 	char			res[XT_MAX_URL_LENGTH + 32] = ":";
 	char			*sc = s;