diff --git a/Makefile.in b/Makefile.in index 42027d6..7241e0c 100644 --- a/Makefile.in +++ b/Makefile.in @@ -35,7 +35,8 @@ RC_DIR = @RC_DIR@ ETC_DIR = $(sysconfdir) CONF_DIR = $(sysconfdir)/$(PACKAGE) -CFLAGS = -Wall -I. -I$(top_srcdir) @CFLAGS@ $(CPPFLAGS) $(DEFS) $(OPTS) +WARNINGS= -Wall -Wnull-dereference +CFLAGS = $(WARNINGS) -I. -I$(top_srcdir) @CFLAGS@ $(CPPFLAGS) $(DEFS) $(OPTS) WCCFLAGS = @WCCFLAGS@ CPPFLAGS = @CPPFLAGS@ DEFS = @DEFS@ -DAUXBIN_DIR=\"$(AUXBIN_DIR)\" \ diff --git a/buffer.c b/buffer.c index 083ecf6..f4a0377 100644 --- a/buffer.c +++ b/buffer.c @@ -707,7 +707,8 @@ readBufferCache(Buffer *buf) cache = fopen(buf->savecache, "r"); if (cache == NULL || fread1(clnum, cache) || fread1(tlnum, cache)) { - fclose(cache); + if (cache != NULL) + fclose(cache); buf->savecache = NULL; return -1; } diff --git a/etc.c b/etc.c index d50adad..805bfa0 100644 --- a/etc.c +++ b/etc.c @@ -1596,7 +1596,8 @@ file_to_url(char *file) char *host = NULL; #endif - file = expandPath(file); + if (!(file = expandPath(file))) + return NULL; #ifdef SUPPORT_NETBIOS_SHARE if (file[0] == '/' && file[1] == '/') { char *p; diff --git a/file.c b/file.c index 2ba18dc..9704cea 100644 --- a/file.c +++ b/file.c @@ -609,7 +609,7 @@ readHeader(URLFile *uf, Buffer *newBuf, int thru, ParsedURL *pu) if (src) newBuf->header_source = tmpf; } - while ((tmp = StrmyUFgets(uf))->length) { + while ((tmp = StrmyUFgets(uf)) && tmp->length) { #ifdef USE_NNTP if (uf->scheme == SCM_NEWS && tmp->ptr[0] == '.') Strshrinkfirst(tmp, 1); @@ -1382,16 +1382,15 @@ AuthDigestCred(struct http_auth *ha, Str uname, Str pw, ParsedURL *pu, */ tmp = Strnew_m_charp("Digest username=\"", uname->ptr, "\"", NULL); - Strcat_m_charp(tmp, ", realm=", - get_auth_param(ha->param, "realm")->ptr, NULL); - Strcat_m_charp(tmp, ", nonce=", - get_auth_param(ha->param, "nonce")->ptr, NULL); + if ((s = get_auth_param(ha->param, "realm")) != NULL) + Strcat_m_charp(tmp, ", realm=", s->ptr, NULL); + if ((s = get_auth_param(ha->param, "nonce")) != NULL) + Strcat_m_charp(tmp, ", nonce=", s->ptr, NULL); Strcat_m_charp(tmp, ", uri=\"", uri->ptr, "\"", NULL); Strcat_m_charp(tmp, ", response=\"", rd->ptr, "\"", NULL); - if (algorithm) - Strcat_m_charp(tmp, ", algorithm=", - get_auth_param(ha->param, "algorithm")->ptr, NULL); + if (algorithm && (s = get_auth_param(ha->param, "algorithm"))) + Strcat_m_charp(tmp, ", algorithm=", s->ptr, NULL); if (cnonce) Strcat_m_charp(tmp, ", cnonce=\"", cnonce->ptr, "\"", NULL); @@ -3105,11 +3104,14 @@ purgeline(struct html_feed_environ *h_env) { char *p, *q; Str tmp; + TextLine *tl; if (h_env->buf == NULL || h_env->blank_lines == 0) return; - p = rpopTextLine(h_env->buf)->line->ptr; + if (!(tl = rpopTextLine(h_env->buf))) + return; + p = tl->line->ptr; tmp = Strnew(); while (*p) { q = p; @@ -6332,7 +6334,7 @@ file_feed() { Str s; s = StrISgets(_file_lp2); - if (s->length == 0) { + if (s && s->length == 0) { ISclose(_file_lp2); return NULL; } @@ -7351,7 +7353,7 @@ loadHTMLstream(URLFile *f, Buffer *newBuf, FILE * src, int internal) #endif if (IStype(f->stream) != IST_ENCODED) f->stream = newEncodedStream(f->stream, f->encoding); - while ((lineBuf2 = StrmyUFgets(f))->length) { + while ((lineBuf2 = StrmyUFgets(f)) && lineBuf2->length) { #ifdef USE_NNTP if (f->scheme == SCM_NEWS && lineBuf2->ptr[0] == '.') { Strshrinkfirst(lineBuf2, 1); @@ -7508,7 +7510,7 @@ loadGopherDir0(URLFile *uf, ParsedURL *pu) pre = 0; while (1) { - if (lbuf = StrUFgets(uf), lbuf->length == 0) + if (!(lbuf = StrUFgets(uf)) || lbuf->length == 0) break; if (lbuf->ptr[0] == '.' && (lbuf->ptr[1] == '\n' || lbuf->ptr[1] == '\r')) @@ -7678,7 +7680,7 @@ loadBuffer(URLFile *uf, Buffer *volatile newBuf) nlines = 0; if (IStype(uf->stream) != IST_ENCODED) uf->stream = newEncodedStream(uf->stream, uf->encoding); - while ((lineBuf2 = StrmyISgets(uf->stream))->length) { + while ((lineBuf2 = StrmyISgets(uf->stream)) && lineBuf2->length) { #ifdef USE_NNTP if (uf->scheme == SCM_NEWS && lineBuf2->ptr[0] == '.') { Strshrinkfirst(lineBuf2, 1); @@ -8102,7 +8104,8 @@ getNextPage(Buffer *buf, int plen) init_stream(&uf, SCM_UNKNOWN, NULL); for (i = 0; i < plen; i++) { - lineBuf2 = StrmyISgets(buf->pagerSource); + if (!(lineBuf2 = StrmyISgets(buf->pagerSource))) + return NULL; if (lineBuf2->length == 0) { /* Assume that `cmd == buf->filename' */ if (buf->filename) @@ -8151,7 +8154,8 @@ getNextPage(Buffer *buf, int plen) l = l->next; } while (l && l->bpos); buf->firstLine = l; - buf->firstLine->prev = NULL; + if (l) + buf->firstLine->prev = NULL; } } pager_end: diff --git a/frame.c b/frame.c index c595c40..be1a961 100644 --- a/frame.c +++ b/frame.c @@ -532,7 +532,7 @@ createFrameFile(struct frameset *f, FILE * f1, Buffer *current, int level, !strcasecmp(frame.body->type, "text/plain")) { Str tmp; fprintf(f1, "
\n");
-		    while ((tmp = StrmyUFgets(&f2))->length) {
+		    while ((tmp = StrmyUFgets(&f2)) && tmp->length) {
 			tmp = convertLine(NULL, tmp, HTML_MODE, &charset,
 					  doc_charset);
 			fprintf(f1, "%s", html_quote(tmp->ptr));
@@ -549,7 +549,7 @@ createFrameFile(struct frameset *f, FILE * f1, Buffer *current, int level,
 		    do {
 			if (*p == '\0') {
 			    Str tmp = StrmyUFgets(&f2);
-			    if (tmp->length == 0)
+			    if (!tmp || tmp->length == 0)
 				break;
 			    tmp = convertLine(NULL, tmp, HTML_MODE, &charset,
 					      doc_charset);
diff --git a/ftp.c b/ftp.c
index 2ca0247..f73d239 100644
--- a/ftp.c
+++ b/ftp.c
@@ -70,7 +70,8 @@ ftp_command(FTP ftp, char *cmd, char *arg, int *status)
     if (!status)
 	return NULL;
     *status = -1;		/* error */
-    tmp = StrISgets(ftp->rf);
+    if (!(tmp = StrISgets(ftp->rf)))
+	return NULL;
     if (IS_DIGIT(tmp->ptr[0]) && IS_DIGIT(tmp->ptr[1]) &&
 	IS_DIGIT(tmp->ptr[2]) && tmp->ptr[3] == ' ')
 	sscanf(tmp->ptr, "%d", status);
@@ -87,7 +88,8 @@ ftp_command(FTP ftp, char *cmd, char *arg, int *status)
      * with the same code, followed immediately by Space , 
      * optionally some text, and the Telnet end-of-line code. */
     while (1) {
-	tmp = StrISgets(ftp->rf);
+	if (!(tmp = StrISgets(ftp->rf)))
+	    break;
 	if (IS_DIGIT(tmp->ptr[0]) && IS_DIGIT(tmp->ptr[1]) &&
 	    IS_DIGIT(tmp->ptr[2]) && tmp->ptr[3] == ' ') {
 	    sscanf(tmp->ptr, "%d", status);
diff --git a/main.c b/main.c
index 0082068..005d9b2 100644
--- a/main.c
+++ b/main.c
@@ -1079,6 +1079,10 @@ main(int argc, char **argv)
 	    newbuf->search_header = search_header;
 	if (CurrentTab == NULL) {
 	    FirstTab = LastTab = CurrentTab = newTab();
+	    if (!FirstTab) {
+		fprintf(stderr, "%s\n","Can't allocated memory");
+		exit(1);
+	    }
 	    nTab = 1;
 	    Firstbuf = Currentbuf = newbuf;
 	}
@@ -6481,8 +6485,8 @@ followTab(TabBuffer * tab)
 	Buffer *c, *p;
 
 	c = Currentbuf;
-	p = prevBuffer(c, buf);
-	p->nextBuffer = NULL;
+	if ((p = prevBuffer(c, buf)))
+	    p->nextBuffer = NULL;
 	Firstbuf = buf;
 	deleteTab(CurrentTab);
 	CurrentTab = tab;
@@ -6522,8 +6526,8 @@ tabURL0(TabBuffer * tab, char *prompt, int relative)
 	Buffer *c, *p;
 
 	c = Currentbuf;
-	p = prevBuffer(c, buf);
-	p->nextBuffer = NULL;
+	if ((p = prevBuffer(c, buf)))
+	    p->nextBuffer = NULL;
 	Firstbuf = buf;
 	deleteTab(CurrentTab);
 	CurrentTab = tab;
diff --git a/news.c b/news.c
index cd76c26..66667e4 100644
--- a/news.c
+++ b/news.c
@@ -51,7 +51,7 @@ news_command(News * news, char *cmd, char *arg, int *status)
 	return NULL;
     *status = -1;
     tmp = StrISgets(news->rf);
-    if (tmp->length)
+    if (tmp && tmp->length)
 	sscanf(tmp->ptr, "%d", status);
     return tmp;
 }
@@ -396,7 +396,8 @@ loadNewsgroup0(ParsedURL *pu)
     if (status == 224) {
 	f.scheme = SCM_NEWS;
 	while (1) {
-	    tmp = StrISgets(current_news.rf);
+	    if (!(tmp = StrISgets(current_news.rf)))
+		break;
 	    if (NEWS_ENDLINE(tmp->ptr))
 		break;
 	    if (sscanf(tmp->ptr, "%d", &i) != 1)
@@ -443,7 +444,7 @@ loadNewsgroup0(ParsedURL *pu)
 		continue;
 	    if (*p == '<')
 		p++;
-	    if (!(q = strchr(p, '>')) && !(q = strchr(p, '\t')))
+	    if ((q = strchr(p, '>')) || (q = strchr(p, '\t')))
 		*q = '\0';
 	    if (!(s = checkHeader(buf, "Subject:")))
 		continue;
@@ -474,7 +475,8 @@ loadNewsgroup0(ParsedURL *pu)
     if (status != 215)
 	goto news_end;
     while (1) {
-	tmp = StrISgets(current_news.rf);
+	if (!(tmp = StrISgets(current_news.rf)))
+	    break;
 	if (NEWS_ENDLINE(tmp->ptr))
 	    break;
 	if (flag < 2) {
diff --git a/w3mimg/fb/fb.c b/w3mimg/fb/fb.c
index 7960584..8abc1af 100644
--- a/w3mimg/fb/fb.c
+++ b/w3mimg/fb/fb.c
@@ -426,11 +426,13 @@ fb_frame_new(int w, int h, int n)
 
     for (i = 0; i < n; i++) {
 	frame[i] = fb_image_new(w, h);
+	if (frame[i] == NULL) {
+	    error = 1;
+	    break;
+	}
 	frame[i]->num = n;
 	frame[i]->id = i;
 	frame[i]->delay = 1000;
-	if (frame[i] == NULL)
-	    error = 1;
     }
 
     if (error) {
diff --git a/w3mimg/fb/fb_imlib2.c b/w3mimg/fb/fb_imlib2.c
index 1a5151c..477d385 100644
--- a/w3mimg/fb/fb_imlib2.c
+++ b/w3mimg/fb/fb_imlib2.c
@@ -84,6 +84,9 @@ draw(FB_IMAGE * img, Imlib_Image image)
     imlib_context_set_image(image);
     data = imlib_image_get_data_for_reading_only();
 
+    if (data == NULL)
+	return;
+
     for (j = 0; j < img->height; j++) {
 	offset = img->width * j;
 	for (i = 0; i < img->width; i++) {