From f7601b4555f51b8e3d6354e13eb32e26cd9c6a03 Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Sun, 3 Oct 2021 12:37:06 +0200 Subject: [PATCH 01/17] Move OPTS to end of CFLAGS This allows the user to override default options. --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 4ca3768..24021d4 100644 --- a/Makefile.in +++ b/Makefile.in @@ -35,7 +35,7 @@ RC_DIR = @RC_DIR@ ETC_DIR = $(sysconfdir) CONF_DIR = $(sysconfdir)/$(PACKAGE) -CFLAGS = $(OPTS) -I. -I$(top_srcdir) @CFLAGS@ $(CPPFLAGS) $(DEFS) +CFLAGS = -I. -I$(top_srcdir) @CFLAGS@ $(CPPFLAGS) $(DEFS) $(OPTS) WCCFLAGS = @WCCFLAGS@ CPPFLAGS = @CPPFLAGS@ DEFS = @DEFS@ -DAUXBIN_DIR=\"$(AUXBIN_DIR)\" \ From 89295504fcc3b9d76813c9de092a6ce97bb575d5 Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Sat, 9 Oct 2021 12:11:46 +0200 Subject: [PATCH 02/17] Suppress two warnings when compiling with tcc While there, add some comments to better understand the code flow in localcgi_post(). --- local.c | 9 ++++++++- main.c | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/local.c b/local.c index 8cae710..a0a5c40 100644 --- a/local.c +++ b/local.c @@ -380,17 +380,19 @@ localcgi_post(char *uri, char *qstr, FormList *request, char *referer) cgi_dir = mydirname(file); #endif cgi_basename = mybasename(file); - pid = open_pipe_rw(&fr, NULL); + pid = open_pipe_rw(&fr, NULL); /* open_pipe_rw() forks */ /* Don't invoke gc after here, or the program might crash in some platforms */ if (pid < 0) { if (fw) fclose(fw); return NULL; } else if (pid) { + /* parent */ if (fw) fclose(fw); return fr; } + /* child */ setup_child(TRUE, 2, fw ? fileno(fw) : -1); set_cgi_environ(name, file, uri); @@ -433,4 +435,9 @@ localcgi_post(char *uri, char *qstr, FormList *request, char *referer) file, cgi_basename, strerror(errno)); exit(1); #endif + /* + * Suppress compiler warning: function might return no value + * This code is never reached. + */ + return NULL; } diff --git a/main.c b/main.c index ced6f40..49d7afe 100644 --- a/main.c +++ b/main.c @@ -394,6 +394,11 @@ die_oom(size_t bytes) { fprintf(stderr, "Out of memory: %lu bytes unavailable!\n", (unsigned long)bytes); exit(1); + /* + * Suppress compiler warning: function might return no value + * This code is never reached. + */ + return NULL; } int From 84f724a5902bcbf4dee12068cab3131996dfe6b4 Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Thu, 2 Sep 2021 20:25:28 +0200 Subject: [PATCH 03/17] Use standard conforming main() definition --- main.c | 2 +- mktable.c | 2 +- proto.h | 2 +- w3mbookmark.c | 2 +- w3mhelperpanel.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/main.c b/main.c index 49d7afe..d6106cb 100644 --- a/main.c +++ b/main.c @@ -402,7 +402,7 @@ die_oom(size_t bytes) } int -main(int argc, char **argv, char **envp) +main(int argc, char **argv) { Buffer *newbuf = NULL; char *p; diff --git a/mktable.c b/mktable.c index 63a8c03..30d691b 100644 --- a/mktable.c +++ b/mktable.c @@ -26,7 +26,7 @@ defhashfunc(HashItem_ss *, int, hss_i) /* *INDENT-ON* */ int -main(int argc, char *argv[], char **envp) +main(int argc, char *argv[]) { FILE *f; Hash_ss *hash; diff --git a/proto.h b/proto.h index 66d497e..40153e8 100644 --- a/proto.h +++ b/proto.h @@ -5,7 +5,7 @@ * * Created: Wed Feb 10 12:47:03 1999 */ -extern int main(int argc, char **argv, char **envp); +extern int main(int argc, char **argv); extern void nulcmd(void); extern void pushEvent(int cmd, void *data); extern MySignalHandler intTrap(SIGNAL_ARG); diff --git a/w3mbookmark.c b/w3mbookmark.c index a306f26..0c9b8fb 100644 --- a/w3mbookmark.c +++ b/w3mbookmark.c @@ -181,7 +181,7 @@ insert_bookmark(char *bmark, struct parsed_tagarg *data) } int -main(int argc, char *argv[], char **envp) +main(int argc, char *argv[]) { extern char *getenv(); char *p; diff --git a/w3mhelperpanel.c b/w3mhelperpanel.c index 96b60a0..bedbba5 100644 --- a/w3mhelperpanel.c +++ b/w3mhelperpanel.c @@ -164,7 +164,7 @@ editMailcap(char *mailcap, struct parsed_tagarg *args) } int -main(int argc, char *argv[], char **envp) +main(int argc, char *argv[]) { Str mailcapfile; extern char *getenv(); From dad5cbe83b09fefb48a99fca42b0f6fefeb4fa97 Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Thu, 2 Sep 2021 21:09:42 +0200 Subject: [PATCH 04/17] Use main(void) when not taking arguments --- scrsize.c | 2 +- w3mbookmark.c | 2 +- w3mhelperpanel.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/scrsize.c b/scrsize.c index b45009a..d71ffd3 100644 --- a/scrsize.c +++ b/scrsize.c @@ -37,7 +37,7 @@ #include int -main() +main(void) { char *cp; Display *dpy; diff --git a/w3mbookmark.c b/w3mbookmark.c index 0c9b8fb..2e64327 100644 --- a/w3mbookmark.c +++ b/w3mbookmark.c @@ -181,7 +181,7 @@ insert_bookmark(char *bmark, struct parsed_tagarg *data) } int -main(int argc, char *argv[]) +main(void) { extern char *getenv(); char *p; diff --git a/w3mhelperpanel.c b/w3mhelperpanel.c index bedbba5..7d13032 100644 --- a/w3mhelperpanel.c +++ b/w3mhelperpanel.c @@ -164,7 +164,7 @@ editMailcap(char *mailcap, struct parsed_tagarg *args) } int -main(int argc, char *argv[]) +main(void) { Str mailcapfile; extern char *getenv(); From 916104b7f2ef5f6a119f4a00b65299236fb0294c Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Thu, 2 Sep 2021 11:53:15 +0200 Subject: [PATCH 05/17] Remove unused variable --- Str.c | 8 +++----- file.c | 4 +--- image.c | 3 +-- istream.c | 3 +-- main.c | 6 ------ menu.c | 3 +-- news.c | 3 +-- 7 files changed, 8 insertions(+), 22 deletions(-) diff --git a/Str.c b/Str.c index f6b7670..ac6446a 100644 --- a/Str.c +++ b/Str.c @@ -520,10 +520,8 @@ Sprintf(char *fmt, ...) case SP_PREC: if (IS_ALPHA(*f)) { /* conversion char. */ - double vd; int vi; char *vs; - void *vp; switch (*f) { case 'l': @@ -545,7 +543,7 @@ Sprintf(char *fmt, ...) case 'e': case 'G': case 'E': - vd = va_arg(ap, double); + va_arg(ap, double); len += (p > 0) ? p : 15; break; case 'c': @@ -558,11 +556,11 @@ Sprintf(char *fmt, ...) len += (p > vi) ? p : vi; break; case 'p': - vp = va_arg(ap, void *); + va_arg(ap, void *); len += 10; break; case 'n': - vp = va_arg(ap, void *); + va_arg(ap, void *); break; } status = SP_NORMAL; diff --git a/file.c b/file.c index 917a673..aeb3bf4 100644 --- a/file.c +++ b/file.c @@ -3803,7 +3803,7 @@ process_button(struct parsed_tag *tag) { Str tmp = NULL; char *p, *q, *r, *qq = ""; - int qlen, v; + int v; if (cur_form_id < 0) { char *s = ""; @@ -3847,7 +3847,6 @@ process_button(struct parsed_tag *tag) } if (q) { qq = html_quote(q); - qlen = strlen(q); } /* Strcat_charp(tmp, ""); */ @@ -7601,7 +7600,6 @@ loadGopherSearch0(URLFile *uf, ParsedURL *pu) { Str tmp; char *volatile p, *volatile q; - MySignalHandler(*volatile prevtrap) (SIGNAL_ARG) = NULL; #ifdef USE_M17N wc_ces doc_charset = DocumentCharset; #endif diff --git a/image.c b/image.c index a84d974..a06655e 100644 --- a/image.c +++ b/image.c @@ -551,13 +551,12 @@ loadImage(Buffer *buf, int flag) } #else /* !DONT_CALL_GC_AFTER_FORK */ if ((cache->pid = fork()) == 0) { - Buffer *b; /* * setup_child(TRUE, 0, -1); */ setup_child(FALSE, 0, -1); image_source = cache->file; - b = loadGeneralFile(cache->url, cache->current, NULL, 0, NULL); + loadGeneralFile(cache->url, cache->current, NULL, 0, NULL); /* TODO make sure removing this didn't break anything if (!b || !b->real_type || strncasecmp(b->real_type, "image/", 6)) unlink(cache->file); diff --git a/istream.c b/istream.c index 5e432c9..3078f01 100644 --- a/istream.c +++ b/istream.c @@ -418,7 +418,6 @@ ssl_check_cert_ident(X509 * x, char *hostname) if (alt) { int n; GENERAL_NAME *gn; - X509V3_EXT_METHOD *method; Str seen_dnsname = NULL; n = sk_GENERAL_NAME_num(alt); @@ -459,7 +458,7 @@ ssl_check_cert_ident(X509 * x, char *hostname) break; } } - method = X509V3_EXT_get(ex); + X509V3_EXT_get(ex); sk_GENERAL_NAME_free(alt); if (i < n) /* Found a match */ match_ident = TRUE; diff --git a/main.c b/main.c index d6106cb..0082068 100644 --- a/main.c +++ b/main.c @@ -1813,15 +1813,11 @@ static int dispincsrch(int ch, Str buf, Lineprop *prop) { static Buffer sbuf; - static Line *currentLine; - static int pos; char *str; int do_next_search = FALSE; if (ch == 0 && buf == NULL) { SAVE_BUFPOSITION(&sbuf); /* search starting point */ - currentLine = sbuf.currentLine; - pos = sbuf.pos; return -1; } @@ -1870,8 +1866,6 @@ dispincsrch(int ch, Str buf, Lineprop *prop) arrangeCursor(Currentbuf); srchcore(str, searchRoutine); arrangeCursor(Currentbuf); - currentLine = Currentbuf->currentLine; - pos = Currentbuf->pos; } displayBuffer(Currentbuf, B_FORCE_REDRAW); clear_mark(Currentbuf->currentLine); diff --git a/menu.c b/menu.c index b0c890d..3e81501 100644 --- a/menu.c +++ b/menu.c @@ -1100,7 +1100,7 @@ process_mMouse(int btn, int x, int y) { Menu *menu; int mselect, i; - static int press_btn = MOUSE_BTN_RESET, press_x, press_y; + static int press_btn = MOUSE_BTN_RESET, press_y; char c = ' '; menu = CurrentMenu; @@ -1169,7 +1169,6 @@ process_mMouse(int btn, int x, int y) if (btn != MOUSE_BTN4_DOWN_RXVT || press_btn == MOUSE_BTN_RESET) { press_btn = btn; - press_x = x; press_y = y; } else { diff --git a/news.c b/news.c index c0494b7..cd76c26 100644 --- a/news.c +++ b/news.c @@ -235,7 +235,6 @@ InputStream openNewsStream(ParsedURL *pu) { char *host, *mode, *group, *p; - Str tmp; int port, status; if (pu->file == NULL || *pu->file == '\0') @@ -262,7 +261,7 @@ openNewsStream(ParsedURL *pu) mode = NULL; if (current_news.host) { if (!strcmp(current_news.host, host) && current_news.port == port) { - tmp = news_command(¤t_news, "MODE", mode ? mode : "READER", + news_command(¤t_news, "MODE", mode ? mode : "READER", &status); if (status != 200 && status != 201) news_close(¤t_news); From 4901408ea5ea167696175a5da3c92e709702ca4f Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Mon, 13 Sep 2021 19:47:02 +0200 Subject: [PATCH 06/17] Fix warning for unused variable without USE_M17N --- display.c | 6 ++---- etc.c | 4 +++- file.c | 3 +-- linein.c | 2 -- table.c | 2 +- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/display.c b/display.c index e62d07f..a45fc3e 100644 --- a/display.c +++ b/display.c @@ -1368,15 +1368,14 @@ cursorRight(Buffer *buf, int n) { int i, delta = 1, cpos, vpos2; Line *l = buf->currentLine; - Lineprop *p; if (buf->firstLine == NULL) return; if (buf->pos == l->len && !(l->next && l->next->bpos)) return; i = buf->pos; - p = l->propBuf; #ifdef USE_M17N + Lineprop *p = l->propBuf; while (i + delta < l->len && p[i + delta] & PC_WCHAR2) delta++; #endif @@ -1419,13 +1418,12 @@ cursorLeft(Buffer *buf, int n) { int i, delta = 1, cpos; Line *l = buf->currentLine; - Lineprop *p; if (buf->firstLine == NULL) return; i = buf->pos; - p = l->propBuf; #ifdef USE_M17N + Lineprop *p = l->propBuf; while (i - delta > 0 && p[i - delta] & PC_WCHAR2) delta++; #endif diff --git a/etc.c b/etc.c index aeb65ec..0df0888 100644 --- a/etc.c +++ b/etc.c @@ -253,8 +253,10 @@ checkType(Str s, Lineprop **oprop, Linecolor **ocolor) char *es = NULL; #endif int do_copy = FALSE; +#ifdef USE_M17N int i; int plen = 0, clen; +#endif if (prop_size < s->length) { prop_size = (s->length > LINELEN) ? s->length : LINELEN; @@ -429,7 +431,6 @@ checkType(Str s, Lineprop **oprop, Linecolor **ocolor) } #endif - plen = get_mclen(str); mode = get_mctype(str) | effect; #ifdef USE_ANSI_COLOR if (color) { @@ -439,6 +440,7 @@ checkType(Str s, Lineprop **oprop, Linecolor **ocolor) #endif *(prop++) = mode; #ifdef USE_M17N + plen = get_mclen(str); if (plen > 1) { mode = (mode & ~PC_WCHAR1) | PC_WCHAR2; for (i = 1; i < plen; i++) { diff --git a/file.c b/file.c index aeb3bf4..04c2872 100644 --- a/file.c +++ b/file.c @@ -8164,7 +8164,6 @@ int save2tmp(URLFile uf, char *tmpf) { FILE *ff; - int check; clen_t linelen = 0, trbyte = 0; MySignalHandler(*volatile prevtrap) (SIGNAL_ARG) = NULL; static JMP_BUF env_bak; @@ -8181,8 +8180,8 @@ save2tmp(URLFile uf, char *tmpf) goto _end; } TRAP_ON; - check = 0; #ifdef USE_NNTP + int check = 0; if (uf.scheme == SCM_NEWS) { char c; while (c = UFgetc(&uf), !iseos(uf.stream)) { diff --git a/linein.c b/linein.c index 22b4ac8..b58cad6 100644 --- a/linein.c +++ b/linein.c @@ -77,8 +77,6 @@ static Str strCurrentBuf; static int use_hist; #ifdef USE_M17N static void ins_char(Str str); -#else -static void ins_char(char c); #endif char * diff --git a/table.c b/table.c index a8e6598..0a43156 100644 --- a/table.c +++ b/table.c @@ -419,7 +419,7 @@ suspend_or_pushdata(struct table *tbl, char *line) #ifdef USE_M17N #define PUSH_TAG(str,n) Strcat_charp_n(tagbuf, str, n) #else -#define PUSH_TAG(str,n) Strcat_char(tagbuf, *str) +#define PUSH_TAG(str,n) Strcat_char(tagbuf, *str), (void)n #endif int visible_length_offset = 0; From ab22479fb3483e0094231788f730bb63de9f4355 Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Mon, 13 Sep 2021 20:10:13 +0200 Subject: [PATCH 07/17] Fix warning for unused variable w/o MENU_SELECT --- file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/file.c b/file.c index 04c2872..5da7ecd 100644 --- a/file.c +++ b/file.c @@ -4001,7 +4001,6 @@ void process_option(void) { char begin_char = '[', end_char = ']'; - int len; if (cur_select == NULL || cur_option == NULL) return; @@ -4012,6 +4011,7 @@ process_option(void) if (cur_option_label == NULL) cur_option_label = cur_option; #ifdef MENU_SELECT + int len; if (!select_is_multiple) { len = get_Str_strwidth(cur_option_label); if (len > cur_option_maxwidth) From 0cd26b92cbeb93b70343e4e110030fbd5f74bcb9 Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Sat, 11 Sep 2021 19:42:19 +0200 Subject: [PATCH 08/17] Take the correct char type in growbuf_append() This change removes all warnings (-Wall) from this function. --- indep.c | 2 +- indep.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/indep.c b/indep.c index 055e19e..4d13a3f 100644 --- a/indep.c +++ b/indep.c @@ -821,7 +821,7 @@ growbuf_reserve(struct growbuf *gb, int leastarea) } void -growbuf_append(struct growbuf *gb, const char *src, int len) +growbuf_append(struct growbuf *gb, const unsigned char *src, int len) { growbuf_reserve(gb, gb->length + len); memcpy(&gb->ptr[gb->length], src, len); diff --git a/indep.h b/indep.h index 5c6b1da..b123c85 100644 --- a/indep.h +++ b/indep.h @@ -83,7 +83,7 @@ extern void growbuf_init_without_GC(struct growbuf *gb); extern void growbuf_clear(struct growbuf *gb); extern Str growbuf_to_Str(struct growbuf *gb); extern void growbuf_reserve(struct growbuf *gb, int leastarea); -extern void growbuf_append(struct growbuf *gb, const char *src, int len); +extern void growbuf_append(struct growbuf *gb, const unsigned char *src, int len); #define GROWBUF_ADD_CHAR(gb,ch) ((((gb)->length>=(gb)->area_size)?growbuf_reserve(gb,(gb)->length+1):(void)0),(void)((gb)->ptr[(gb)->length++] = (ch))) extern char *w3m_auxbin_dir(); From b25abc595ca146b6b3e1590055a57353cc96098c Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Sat, 4 Sep 2021 12:48:55 +0200 Subject: [PATCH 09/17] Let strncpy write the null terminator --- terms.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terms.c b/terms.c index ad306d6..ae42cbf 100644 --- a/terms.c +++ b/terms.c @@ -356,7 +356,7 @@ char *ttyname(int); #define SETCHMODE(var,mode) ((var) = (((var)&~C_WHICHCHAR) | mode)) #ifdef USE_M17N #define SETCH(var,ch,len) ((var) = New_Reuse(char, (var), (len) + 1), \ - strncpy((var), (ch), (len)), (var)[len] = '\0') + strncpy((var), (ch), (len + 1))) #else #define SETCH(var,ch,len) ((var) = (ch)) #endif From 561f27f8330608c03562e0eb1f490d2e1595064c Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Sat, 4 Sep 2021 12:15:27 +0200 Subject: [PATCH 10/17] Explicitly cast to unsigned when passing to MD5() --- file.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/file.c b/file.c index 5da7ecd..ddc6214 100644 --- a/file.c +++ b/file.c @@ -1290,7 +1290,7 @@ AuthDigestCred(struct http_auth *ha, Str uname, Str pw, ParsedURL *pu, tmp = Strnew_m_charp(uname->ptr, ":", qstr_unquote(get_auth_param(ha->param, "realm"))->ptr, ":", pw->ptr, NULL); - MD5(tmp->ptr, strlen(tmp->ptr), md5); + MD5((unsigned char *)tmp->ptr, strlen(tmp->ptr), md5); a1buf = digest_hex(md5); if (algorithm) { @@ -1303,7 +1303,7 @@ AuthDigestCred(struct http_auth *ha, Str uname, Str pw, ParsedURL *pu, tmp = Strnew_m_charp(a1buf->ptr, ":", qstr_unquote(nonce)->ptr, ":", qstr_unquote(cnonce)->ptr, NULL); - MD5(tmp->ptr, strlen(tmp->ptr), md5); + MD5((unsigned char *)tmp->ptr, strlen(tmp->ptr), md5); a1buf = digest_hex(md5); } else if (strcasecmp(algorithm->ptr, "MD5") == 0) @@ -1325,23 +1325,23 @@ AuthDigestCred(struct http_auth *ha, Str uname, Str pw, ParsedURL *pu, Str ebody; ebody = Strfgetall(fp); fclose(fp); - MD5(ebody->ptr, strlen(ebody->ptr), md5); + MD5((unsigned char *)ebody->ptr, strlen(ebody->ptr), md5); } else { - MD5("", 0, md5); + MD5((unsigned char *)"", 0, md5); } } else { - MD5(request->body, request->length, md5); + MD5((unsigned char *)request->body, request->length, md5); } } else { - MD5("", 0, md5); + MD5((unsigned char *)"", 0, md5); } Strcat_char(tmp, ':'); Strcat(tmp, digest_hex(md5)); } - MD5(tmp->ptr, strlen(tmp->ptr), md5); + MD5((unsigned char *)tmp->ptr, strlen(tmp->ptr), md5); a2buf = digest_hex(md5); if (qop_i >= QOP_AUTH) { @@ -1359,7 +1359,7 @@ AuthDigestCred(struct http_auth *ha, Str uname, Str pw, ParsedURL *pu, ":", qstr_unquote(cnonce)->ptr, ":", qop_i == QOP_AUTH ? "auth" : "auth-int", ":", a2buf->ptr, NULL); - MD5(tmp->ptr, strlen(tmp->ptr), md5); + MD5((unsigned char *)tmp->ptr, strlen(tmp->ptr), md5); rd = digest_hex(md5); } else { @@ -1369,7 +1369,7 @@ AuthDigestCred(struct http_auth *ha, Str uname, Str pw, ParsedURL *pu, tmp = Strnew_m_charp(a1buf->ptr, ":", qstr_unquote(get_auth_param(ha->param, "nonce"))-> ptr, ":", a2buf->ptr, NULL); - MD5(tmp->ptr, strlen(tmp->ptr), md5); + MD5((unsigned char *)tmp->ptr, strlen(tmp->ptr), md5); rd = digest_hex(md5); } From cf7058b56c771c58e36d59df1488d22d42be35ee Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Sun, 12 Sep 2021 11:47:38 +0200 Subject: [PATCH 11/17] Let base64_encode() take a char * Throughout the whole code base only char * is passed, but a unsigned char * is expected. This leads to several warnings. Fix the interface and cast to unsigned char * internally to avoid any changes to the behaviour. --- etc.c | 14 ++++++++------ proto.h | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/etc.c b/etc.c index 0df0888..d50adad 100644 --- a/etc.c +++ b/etc.c @@ -2021,13 +2021,15 @@ static char Base64Table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; Str -base64_encode(const unsigned char *src, size_t len) +base64_encode(const char *src, size_t len) { Str dest; - const unsigned char *in, *endw; + const unsigned char *in, *endw, *s; unsigned long j; size_t k; + s = (unsigned char*)src; + k = len; if (k % 3) k += 3 - (k % 3); @@ -2043,9 +2045,9 @@ base64_encode(const unsigned char *src, size_t len) return Strnew(); } - in = src; + in = s; - endw = src + len - 2; + endw = s + len - 2; while (in < endw) { j = *in++; @@ -2058,9 +2060,9 @@ base64_encode(const unsigned char *src, size_t len) Strcatc(dest, Base64Table[j & 0x3f]); } - if (src + len - in) { + if (s + len - in) { j = *in++; - if (src + len - in) { + if (s + len - in) { j = j << 8 | *in++; j = j << 8; Strcatc(dest, Base64Table[(j >> 18) & 0x3f]); diff --git a/proto.h b/proto.h index 40153e8..d87a31e 100644 --- a/proto.h +++ b/proto.h @@ -831,4 +831,4 @@ void srand48(long); long lrand48(void); #endif -extern Str base64_encode(const unsigned char *src, size_t len); +extern Str base64_encode(const char *src, size_t len); From c5c63a1a3daaee0b7874484cc0aa9cbad096bf82 Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Mon, 30 Aug 2021 20:09:11 +0200 Subject: [PATCH 12/17] Fix a potential buffer overflow When compiling with -Wformat-overflow=2 GCC reports: note: 'sprintf' output between 16 and 35 bytes into a destination of size 32 --- buffer.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buffer.c b/buffer.c index e70cffe..083ecf6 100644 --- a/buffer.c +++ b/buffer.c @@ -239,7 +239,7 @@ writeBufferName(Buffer *buf, int n) void gotoLine(Buffer *buf, int n) { - char msg[32]; + char msg[36]; Line *l = buf->firstLine; if (l == NULL) @@ -284,7 +284,7 @@ gotoLine(Buffer *buf, int n) void gotoRealLine(Buffer *buf, int n) { - char msg[32]; + char msg[36]; Line *l = buf->firstLine; if (l == NULL) From d3ea4b33f19a7950f3cb42a85f8d800e6b04c6f1 Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Sat, 4 Sep 2021 12:22:46 +0200 Subject: [PATCH 13/17] Initialize struct before use --- table.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/table.c b/table.c index 0a43156..9d99bb3 100644 --- a/table.c +++ b/table.c @@ -1524,7 +1524,7 @@ check_table_height(struct table *t) short maxcell; short size; int *height; - } cell; + } cell = {0}; int space = 0; cell.size = 0; From cf2fd623fc426fcb3c259c7e81ddb78eeaff92ed Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Sat, 4 Sep 2021 12:49:32 +0200 Subject: [PATCH 14/17] Use cast to suppress warning --- terms.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terms.c b/terms.c index ae42cbf..e272aab 100644 --- a/terms.c +++ b/terms.c @@ -737,7 +737,7 @@ save_first_animation_frame(const char *path) /* Header */ - if (len != st.st_size || strncmp(header, "GIF89a", 6) != 0) { + if (len != st.st_size || strncmp((char *)header, "GIF89a", 6) != 0) { return NULL; } From 0073ec6daf53e5b2efac997ac212d03c2cd1aa74 Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Wed, 15 Sep 2021 19:08:15 +0200 Subject: [PATCH 15/17] Use unsigned int for image size This removes a warning with -Wall. --- image.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/image.c b/image.c index a06655e..3532040 100644 --- a/image.c +++ b/image.c @@ -733,7 +733,7 @@ getImageSize(ImageCache * cache) { Str tmp; FILE *f; - int w = 0, h = 0; + unsigned int w = 0, h = 0; if (!activeImage) return FALSE; @@ -751,7 +751,7 @@ getImageSize(ImageCache * cache) f = popen(tmp->ptr, "r"); if (!f) return FALSE; - while (fscanf(f, "%d %d", &w, &h) < 0) { + while (fscanf(f, "%u %u", &w, &h) < 0) { if (feof(f)) break; } From bf40283a803ab76f35ef966e4382ada1d01fe5fd Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Sun, 12 Sep 2021 12:06:43 +0200 Subject: [PATCH 16/17] Enable -Wall by default --- Makefile.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 24021d4..42027d6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -35,7 +35,7 @@ RC_DIR = @RC_DIR@ ETC_DIR = $(sysconfdir) CONF_DIR = $(sysconfdir)/$(PACKAGE) -CFLAGS = -I. -I$(top_srcdir) @CFLAGS@ $(CPPFLAGS) $(DEFS) $(OPTS) +CFLAGS = -Wall -I. -I$(top_srcdir) @CFLAGS@ $(CPPFLAGS) $(DEFS) $(OPTS) WCCFLAGS = @WCCFLAGS@ CPPFLAGS = @CPPFLAGS@ DEFS = @DEFS@ -DAUXBIN_DIR=\"$(AUXBIN_DIR)\" \ From 5b33d9f239db1967e4e2a44edfe64b7c82af65ef Mon Sep 17 00:00:00 2001 From: Rene Kita Date: Sun, 26 Dec 2021 13:35:29 +0100 Subject: [PATCH 17/17] Cast away a warning under OpenBSD 7.0 --- symbol.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/symbol.c b/symbol.c index c047c56..0db82c5 100644 --- a/symbol.c +++ b/symbol.c @@ -181,7 +181,7 @@ push_symbol(Str str, char symbol, int width, int n) #endif p = alt_symbol[(unsigned char)symbol % N_SYMBOL]; for (i = 0; i < 2 && *p; i++, p++) - buf[i] = (*p == ' ') ? NBSP_CODE : *p; + buf[i] = (*p == ' ') ? (char)NBSP_CODE : *p; Strcat(str, Sprintf("<_SYMBOL TYPE=%d>", symbol)); for (; n > 0; n--)