Permalink
Browse files

Enable many warnings & fix them

  • Loading branch information...
1 parent 02a8314 commit 3fcb0808919e48ed6db0cfce8c6d880454899faa ec429 committed Jan 6, 2011
Showing with 63 additions and 64 deletions.
  1. +1 −1 Makefile
  2. +8 −8 bits.c
  3. +3 −3 bits.h
  4. +13 −15 buffer.c
  5. +3 −3 config.c
  6. +7 −7 config.h
  7. +7 −7 input.c
  8. +7 −6 irc.c
  9. +4 −4 irc.h
  10. +4 −4 names.c
  11. +4 −4 names.h
  12. +2 −2 quirc.c
View
2 Makefile
@@ -1,7 +1,7 @@
# Makefile for quIRC
CC ?= gcc
-CFLAGS ?= -Wall
+CFLAGS ?= -Wall -Wextra -Werror -pedantic -std=gnu99 -g
AWK ?= gawk
VERSION := `git describe --tags`
PREFIX ?= /usr/local
View
16 bits.c
@@ -19,16 +19,16 @@ char * fgetl(FILE *fp)
return(lout);
}
-int wordline(const char *msg, int x, char **out, colour lc)
+int wordline(const char *msg, unsigned int x, char **out, colour lc)
{
- int tabx=x;
+ unsigned int tabx=x;
if((!tabx) || (tabx*2>width))
tabx=8;
int l,i,l2,i2;
i=strlen(*out);
l=i+1;
char *word;
- char *ptr=msg;
+ const char *ptr=msg;
while(*ptr)
{
switch(*ptr)
@@ -80,7 +80,7 @@ int wordline(const char *msg, int x, char **out, colour lc)
{
int fore=0, back=0;
ssize_t bytes=0;
- if(sscanf(ptr, "\003%u,%u%zn", &fore, &back, &bytes)==2)
+ if(sscanf(ptr, "\003%d,%d%zn", &fore, &back, &bytes)==2)
{
ptr+=bytes;
if(mirc_colour_compat==2)
@@ -89,7 +89,7 @@ int wordline(const char *msg, int x, char **out, colour lc)
s_setcol(mcc.fore, mcc.back, mcc.hi, mcc.ul, &word, &l2, &i2);
}
}
- else if(sscanf(ptr, "\003%u%zn", &fore, &bytes)==1)
+ else if(sscanf(ptr, "\003%d%zn", &fore, &bytes)==1)
{
ptr+=bytes;
if(mirc_colour_compat==2)
@@ -173,7 +173,7 @@ void append_char(char **buf, int *l, int *i, char c)
void append_str(char **buf, int *l, int *i, const char *str)
{
- while(*str) // not the most tremendously efficient implementation, but conceptually simple at least
+ while(str && *str) // not the most tremendously efficient implementation, but conceptually simple at least
{
append_char(buf, l, i, *str++);
}
@@ -187,7 +187,7 @@ void init_char(char **buf, int *l, int *i)
*i=0;
}
-void crush(char **buf, int len)
+void crush(char **buf, unsigned int len)
{
if(strlen(*buf)>len)
{
@@ -209,7 +209,7 @@ void crush(char **buf, int len)
}
}
-void scrush(char **buf, int len)
+void scrush(char **buf, unsigned int len)
{
if(strlen(*buf)>len)
{
View
6 bits.h
@@ -24,10 +24,10 @@ char *strndup(const char *s, size_t size);
#endif
char * fgetl(FILE *); // gets a line of string data; returns a malloc-like pointer
-int wordline(const char *msg, int x, char **out, colour lc); // prepares a string for printing, breaking lines in between words
+int wordline(const char *msg, unsigned int x, char **out, colour lc); // prepares a string for printing, breaking lines in between words
void init_char(char **buf, int *l, int *i); // initialises a string buffer in heap. *buf becomes a malloc-like pointer
void append_char(char **buf, int *l, int *i, char c); // adds a character to a string buffer in heap (and realloc()s if needed)
void append_str(char **buf, int *l, int *i, const char *str); // adds a string to a string buffer in heap (and realloc()s if needed)
-void crush(char **buf, int len);
-void scrush(char **buf, int len);
+void crush(char **buf, unsigned int len);
+void scrush(char **buf, unsigned int len);
char *mktag(char *fmt, char *from);
View
28 buffer.c
@@ -133,12 +133,10 @@ int init_buffer(int buf, btype type, char *bname, int nlines)
bufs[buf].lt[i]=NULL;
}
bufs[buf].ltag=(char **)malloc(sizeof(char *[nlines]));
- int i;
for(i=0;i<bufs[buf].nlines;i++)
{
bufs[buf].ltag[i]=NULL;
}
- int i;
for(i=0;i<128;i++)
{
bufs[buf].lpt[i]=NULL;
@@ -306,11 +304,11 @@ int render_buffer(int buf)
{
if(bufs[buf].rendered)
return(0); // nothing to do
- int l=start;
+ int l=bufs[buf].start;
int pl;
for(pl=0;pl<PBUFSIZ;pl++)
{
- if(bufs[buf].lpt[pl]) free(bufs[buf].lpt[pl];
+ if(bufs[buf].lpt[pl]) free(bufs[buf].lpt[pl]);
bufs[buf].lpt[pl]=NULL;
}
pl=0;
@@ -321,16 +319,16 @@ int render_buffer(int buf)
char *curline=NULL, *last=NULL, *n=NULL;
bool filled=false;
int overfill=0;
- while(!(bot && (((bufs[buf].pscrbot-height-(overfill%PBUFSIZ)+2*PBUFSIZ)%PBUFSIZ)>((pl-bufs[buf].pscrbot+PBUFSIZ)%PBUFSIZ))))
+ while(!(bot && (((bufs[buf].pscrbot-(signed)height-(overfill%PBUFSIZ)+2*PBUFSIZ)%PBUFSIZ)>((pl-bufs[buf].pscrbot+PBUFSIZ)%PBUFSIZ))))
{
if(!curline)
{
if(last) free(last); last=NULL;
- char *tag;int ci,cl;
+ int ci,cl;
init_char(&curline, &cl, &ci);
s_setcolour(bufs[buf].lc[l], &curline, &cl, &ci);
append_str(&curline, &cl, &ci, bufs[buf].ltag[l]);
- wordline(bufs[buf].lt[l], strlen(curline), &curline, bufs[buf].lc);
+ wordline(bufs[buf].lt[l], strlen(curline), &curline, bufs[buf].lc[l]);
if(full_width_colour)
{
append_str(&curline, &cl, &ci, CLR);
@@ -342,16 +340,15 @@ int render_buffer(int buf)
append_str(&curline, &cl, &ci, CLR);
}
append_char(&curline, &cl, &ci, '\n');
- n=strchr(out, '\n');
- free(ltd);
+ n=strchr(curline, '\n');
last=curline;
apl=0;
}
- if(!*n) n=NULL;
+ if(n&&!*n) n=NULL;
char oldc;
if(n)
{
- oldc=*n++;
+ oldc=*++n;
*n=0;
}
if(as)
@@ -433,6 +430,7 @@ int render_buffer(int buf)
bufs[buf].pstart=0;
}
if(last) free(last); last=NULL;
+ return(0);
}
int buf_print(int buf, colour lc, char *lt)
@@ -550,7 +548,7 @@ void in_update(iline inp)
resetcol();
printf("\n");
// input
- if(inp.left.i+inp.right.i+1<width)
+ if((unsigned)inp.left.i+(unsigned)inp.right.i+1<width)
{
char *lh=highlight(inp.left.data?inp.left.data:"");
char *rh=highlight(inp.right.data?inp.right.data:"");
@@ -750,7 +748,7 @@ void titlebar(void)
{
printf(LOCATE CLA, 1, 1);
setcol(0, 7, true, false);
- int gits;
+ unsigned int gits;
sscanf(VERSION_TXT, "%u", &gits);
const char *hashgit=strchr(VERSION_TXT, ' ');
if(hashgit)
@@ -763,7 +761,7 @@ void titlebar(void)
crush(&cnick, 16);
crush(&cchan, 16);
char tbar[width];
- int wleft=width-1;
+ unsigned int wleft=width-1;
bool use[8]; // #chan nick quIRC version gits ghashgit server topic...
char version[32];
sprintf(version, "%hhu.%hhu.%hhu", VERSION_MAJ, VERSION_MIN, VERSION_REV);
@@ -815,7 +813,7 @@ void titlebar(void)
{
use[7]=true;
}
- int i;
+ unsigned int i;
for(i=0;i<width;i++)
tbar[i]='-';
tbar[width]=0;
View
6 config.c
@@ -298,19 +298,19 @@ int rcread(FILE *rcfp)
sscanf(rest, "%u", &mirc_colour_compat);
else if(strcmp(cmd, "fwc")==0)
{
- int fwc;
+ unsigned int fwc;
sscanf(rest, "%u", &fwc);
full_width_colour=fwc;
}
else if(strcmp(cmd, "hts")==0)
{
- int hts;
+ unsigned int hts;
sscanf(rest, "%u", &hts);
hilite_tabstrip=hts;
}
else if(strcmp(cmd, "tsb")==0)
{
- int ntsb;
+ unsigned int ntsb;
sscanf(rest, "%u", &ntsb);
tsb=ntsb;
}
View
14 config.h
@@ -41,21 +41,21 @@ servlist;
#include "buffer.h"
// global settings & state
-int width, height; // term size
-int mirc_colour_compat;
-int force_redraw;
-int buflines;
-int maxnlen;
+unsigned int width, height; // term size
+unsigned int mirc_colour_compat;
+unsigned int force_redraw;
+unsigned int buflines;
+unsigned int maxnlen;
bool full_width_colour;
bool hilite_tabstrip;
bool tsb; // top status bar
bool autojoin;
char *username, *fname, *nick, *portno;
servlist *servs;
name *igns;
-int tping; // ping timeout
+unsigned int tping; // ping timeout
#ifdef HAVE_DEBUG
-int debug;
+unsigned int debug;
#endif // HAVE_DEBUG
char version[16+strlen(VERSION_TXT)];
View
14 input.c
@@ -244,7 +244,7 @@ int inputchar(iline *inp, int *state)
{
if(d=='5') // C-PgUp
{
- bufs[cbuf].scroll=min(bufs[cbuf].scroll+height-3, bufs[cbuf].filled?bufs[cbuf].nlines-1:bufs[cbuf].ptr-1);
+ bufs[cbuf].scroll=min(bufs[cbuf].scroll+(signed)height-3, bufs[cbuf].filled?bufs[cbuf].nlines-1:bufs[cbuf].ptr-1);
redraw_buffer();
}
else // d=='6' // C-PgDn
@@ -261,7 +261,7 @@ int inputchar(iline *inp, int *state)
case '~':
if(d=='5') // PgUp
{
- bufs[cbuf].input.scroll=min(bufs[cbuf].input.scroll+height, bufs[cbuf].input.filled?bufs[cbuf].input.nlines-1:bufs[cbuf].input.ptr);
+ bufs[cbuf].input.scroll=min(bufs[cbuf].input.scroll+(signed)height, bufs[cbuf].input.filled?bufs[cbuf].input.nlines-1:bufs[cbuf].input.ptr);
}
else // d=='6' // PgDn
{
@@ -393,7 +393,7 @@ char * slash_dequote(char *inp)
{
size_t l=strlen(inp)+1;
char *rv=(char *)malloc(l+1); // we only get shorter, so this will be enough
- int o=0;
+ unsigned int o=0;
while((*inp) && (o<l)) // o>=l should never happen, but it's covered just in case
{
if(*inp=='\\') // \n, \r, \\, \ooo (\0 remains escaped)
@@ -620,7 +620,7 @@ int cmd_handle(char *inp, char **qmsg, fd_set *master, int *fdmax) // old state=
{
if(val)
{
- int fwc;
+ unsigned int fwc;
sscanf(val, "%u", &fwc);
full_width_colour=fwc;
}
@@ -641,7 +641,7 @@ int cmd_handle(char *inp, char **qmsg, fd_set *master, int *fdmax) // old state=
{
if(val)
{
- int hts;
+ unsigned int hts;
sscanf(val, "%u", &hts);
hilite_tabstrip=hts;
}
@@ -662,7 +662,7 @@ int cmd_handle(char *inp, char **qmsg, fd_set *master, int *fdmax) // old state=
{
if(val)
{
- int ntsb;
+ unsigned int ntsb;
sscanf(val, "%u", &ntsb);
tsb=ntsb;
}
@@ -1417,7 +1417,7 @@ int cmd_handle(char *inp, char **qmsg, fd_set *master, int *fdmax) // old state=
}
else if(strcmp(arg, "-l")==0)
{
- i_list(cbuf);
+ i_list();
break;
}
else if(strcmp(arg, "--")==0)
View
13 irc.c
@@ -10,7 +10,8 @@
void handle_sigpipe(int sig)
{
- sigpipe=1;
+ if(sig==SIGPIPE)
+ sigpipe=1;
}
int irc_connect(char *server, char *portno, fd_set *master, int *fdmax)
@@ -1257,7 +1258,7 @@ int ctcp(char *msg, char *from, char *src, int b2, bool ha, bool notice, bool pr
{
if(notice)
{
- char *tag=mktag("(from %s) ", from);
+ char *tag=mktag(priv?"(%s) ":"(from %s) ", from);
w_buf_print(b2, c_notice[1], msg, tag);
free(tag);
if(ha)
@@ -1274,7 +1275,7 @@ int ctcp(char *msg, char *from, char *src, int b2, bool ha, bool notice, bool pr
{
if(notice)
{
- char *tag=mktag("(from %s) ", from);
+ char *tag=mktag(priv?"(%s) ":"(from %s) ", from);
w_buf_print(b2, c_notice[1], msg, tag);
free(tag);
if(ha)
@@ -1291,7 +1292,7 @@ int ctcp(char *msg, char *from, char *src, int b2, bool ha, bool notice, bool pr
{
if(notice)
{
- char *tag=mktag("(from %s) ", from);
+ char *tag=mktag(priv?"(%s) ":"(from %s) ", from);
w_buf_print(b2, c_notice[1], msg, tag);
free(tag);
if(ha)
@@ -1308,7 +1309,7 @@ int ctcp(char *msg, char *from, char *src, int b2, bool ha, bool notice, bool pr
{
if(notice)
{
- char *tag=mktag("(from %s) ", from);
+ char *tag=mktag(priv?"(%s) ":"(from %s) ", from);
w_buf_print(b2, c_notice[1], msg, tag);
free(tag);
if(ha)
@@ -1323,7 +1324,7 @@ int ctcp(char *msg, char *from, char *src, int b2, bool ha, bool notice, bool pr
}
else
{
- char *tag=mktag("(from %s) ", from);
+ char *tag=mktag(priv?"(%s) ":"(from %s) ", from);
w_buf_print(b2, c_notice[1], msg, tag);
if(ha)
bufs[b2].hi_alert=5;
View
8 irc.h
@@ -1,9 +1,9 @@
#pragma once
/*
- quIRC - simple terminal-based IRC client
- Copyright (C) 2010 Edward Cree
-
+ quIRC - simple terminal-based IRC client
+ Copyright (C) 2010 Edward Cree
+
See quirc.c for license information
irc: networking functions
*/
@@ -51,7 +51,7 @@ message;
volatile sig_atomic_t sigpipe;
-void handle_sigpipe(int sig);
+void handle_sigpipe(int);
int irc_connect(char *server, char *portno, fd_set *master, int *fdmax); // non-blocking
int irc_conn_rest(int b, char *nick, char *username, char *fullname); // call this when the non-blocking connect() has finished
View
8 names.c
@@ -1,7 +1,7 @@
/*
- quIRC - simple terminal-based IRC client
- Copyright (C) 2010 Edward Cree
-
+ quIRC - simple terminal-based IRC client
+ Copyright (C) 2010 Edward Cree
+
See quirc.c for license information
names: handling for name lists
*/
@@ -199,7 +199,7 @@ int i_cull(name ** list, char *nm)
return(rv);
}
-void i_list(int b)
+void i_list(void)
{
int count=0;
if(bufs[cbuf].type==CHANNEL)
View
8 names.h
@@ -1,9 +1,9 @@
#pragma once
/*
- quIRC - simple terminal-based IRC client
- Copyright (C) 2010 Edward Cree
-
+ quIRC - simple terminal-based IRC client
+ Copyright (C) 2010 Edward Cree
+
See quirc.c for license information
names: handling for name lists
*/
@@ -33,4 +33,4 @@ void n_free(name * list);
int i_match(name * list, char *nm, bool pm, cmap casemapping); // returns number of matches
int i_cull(name ** list, char *nm); // returns number of instances culled
-void i_list(int b);
+void i_list(void);
View
4 quirc.c
@@ -105,7 +105,7 @@ int main(int argc, char *argv[])
return(1);
}
- int i;
+ unsigned int i;
for(i=0;i<height;i++) // push old stuff off the top of the screen, so it's preserved
printf("\n");
@@ -150,7 +150,7 @@ int main(int argc, char *argv[])
{
if(bufs[b].type==SERVER)
{
- int idle=now-bufs[b].last;
+ unsigned int idle=now-bufs[b].last;
if(tping && (idle>tping)) // a tping value of 0 means "don't ping"
{
if(bufs[b].ping)

0 comments on commit 3fcb080

Please sign in to comment.