* [Edbrowse-dev] [patch] Parenthesize assignments used as a truth value
@ 2014-08-08 11:08 Paul Onyschuk
0 siblings, 0 replies; only message in thread
From: Paul Onyschuk @ 2014-08-08 11:08 UTC (permalink / raw)
To: Edbrowse-dev
[-- Attachment #1: Type: text/plain, Size: 1122 bytes --]
This fixes some of the warnings emitted by a compiler, when
-Wparentheses flag is used. For readability reasons I limited a scope
of the patch to assignments used as a truth value, leaving out warnings
over a precedence of logical operators. Example of a code, that the
warning is emitted for:
if (t = map)
I was bit hesitant with sending a patch. How multiple parentheses
affect readability of a code for users with screen readers? If this
patch has negative impact, I wil understand if it isn't commited.
Still diff is work looking alone for possible mistypes of an equality
operator.
Bellow is diffstat information regarding patch - first number describes
inserted lines, second deleted lines, followed by filename.
$ git diff --numstat
6 6 src/buffers.c
3 3 src/cookies.c
1 1 src/fetchmail.c
8 8 src/format.c
5 5 src/html.cpp
4 4 src/http.c
1 1 src/jsdom.cpp
2 2 src/jsloc.cpp
1 1 src/main.c
7 7 src/sendmail.c
7 7 src/stringfile.c
4 4 src/url.c
--
Paul Onyschuk
[-- Attachment #2: assignment-as-truth.patch --]
[-- Type: application/octet-stream, Size: 14381 bytes --]
diff --git a/src/buffers.c b/src/buffers.c
index 143adc3..aa6171e 100644
--- a/src/buffers.c
+++ b/src/buffers.c
@@ -429,7 +429,7 @@ static void freeWindowLines(struct lineMap *map)
struct lineMap *t;
int cnt = 0;
- if (t = map) {
+ if ((t = map)) {
for (++t; t->text; ++t) {
freeLine(t);
++cnt;
@@ -1815,7 +1815,7 @@ regexpCheck(const char *line, eb_bool isleft, eb_bool ebmuck,
}
}
/* ebmuck tricks */
- while (c = *line) {
+ while ((c = *line)) {
if (e >= re + MAXRE - 3) {
setError(MSG_RexpLong);
return eb_false;
@@ -2321,7 +2321,7 @@ replaceText(const char *line, int len, const char *rhs,
/* copy rhs, watching for $n */
t = rhs;
- while (c = *t) {
+ while ((c = *t)) {
d = t[1];
if (c == '\\') {
t += 2;
@@ -2479,7 +2479,7 @@ static int substituteText(const char *line)
if (*line) { /* third delimiter */
++line;
subPrint = 0;
- while (c = *line) {
+ while ((c = *line)) {
if (c == 'g') {
g_mode = eb_true;
++line;
@@ -3294,12 +3294,12 @@ static eb_bool balanceLine(const char *line)
int level = 0;
int i, direction, forward, backward;
- if (c = *line) {
+ if ((c = *line)) {
if (!strchr(alllist, c) || line[1]) {
setError(MSG_BalanceChar, alllist);
return eb_false;
}
- if (t = strchr(openlist, c)) {
+ if ((t = strchr(openlist, c))) {
d = closelist[t - openlist];
direction = 1;
} else {
diff --git a/src/cookies.c b/src/cookies.c
index efc5ff8..daa894b 100644
--- a/src/cookies.c
+++ b/src/cookies.c
@@ -219,10 +219,10 @@ eb_bool receiveCookie(const char *url, const char *str)
c->server = cloneString(server);
- if (date = extractHeaderParam(str, "expires")) {
+ if ((date = extractHeaderParam(str, "expires"))) {
c->expires = parseHeaderDate(date);
nzFree(date);
- } else if (date = extractHeaderParam(str, "max-age")) {
+ } else if ((date = extractHeaderParam(str, "max-age"))) {
int n = stringIsNum(date);
if (n >= 0) {
time_t now = time(0);
@@ -263,7 +263,7 @@ eb_bool receiveCookie(const char *url, const char *str)
}
}
- if (s = extractHeaderParam(str, "secure")) {
+ if ((s = extractHeaderParam(str, "secure"))) {
c->secure = eb_true;
nzFree(s);
}
diff --git a/src/fetchmail.c b/src/fetchmail.c
index b5d375a..a5b47ae 100644
--- a/src/fetchmail.c
+++ b/src/fetchmail.c
@@ -298,7 +298,7 @@ static void unreadStats(void)
unreadMin = 0;
unreadCount = 0;
- while (f = nextScanFile(mailUnread)) {
+ while ((f = nextScanFile(mailUnread))) {
if (!stringIsNum(f))
continue;
n = atoi(f);
diff --git a/src/format.c b/src/format.c
index 9e9f8b9..7fb46cc 100644
--- a/src/format.c
+++ b/src/format.c
@@ -418,7 +418,7 @@ void anchorSwap(char *buf)
* And c2a0 is a0 is breakspace.
* Then get rid of hyperlinks with absolutely nothing to click on. */
- for (s = w = buf; c = *s; ++s) {
+ for (s = w = buf; (c = *s); ++s) {
d = s[1];
/* utf8 test */
if ((c & 0xc0) == 0xc0 && (d & 0xc0) == 0x80) {
@@ -478,7 +478,7 @@ put1:
/* a represents the state of being in an anchor */
a = 0;
- for (s = buf; c = *s; ++s) {
+ for (s = buf; (c = *s); ++s) {
if (isspaceByte(c)) {
if (!w)
w = s;
@@ -584,7 +584,7 @@ normalChar:
* Get rid of these characters, even in premode.
* Also, remove trailing pipes on a line. */
ss = 0; /* remember location of first pipe */
- for (s = w = buf; c = *s; ++s) {
+ for (s = w = buf; (c = *s); ++s) {
char open, close, linkchar;
if (!strchr("{[(<", c))
goto putc;
@@ -652,7 +652,7 @@ putc:
/* Now compress the implied linebreaks into one. */
premode = eb_false;
- for (s = buf; c = *s; ++s) {
+ for (s = buf; (c = *s); ++s) {
if (c == InternalCodeChar && isdigitByte(s[1])) {
n = strtol(s + 1, &s, 10);
if (*s == '*') {
@@ -1074,7 +1074,7 @@ char *htmlReformat(const char *buf)
/* Insert newlines between adjacent hyperlinks. */
if (c != '}' || premode)
continue;
- for (h = nh; c = *h; ++h)
+ for (h = nh; (c = *h); ++h)
if (!strchr(" \t,:-|;", c))
break;
if (!c || strchr("\r\n\f", c)) {
@@ -1394,7 +1394,7 @@ char *andTranslate(const char *s, eb_bool invisible)
return EMPTYSTRING;
new = initString(&l);
- while (c = *s) {
+ while ((c = *s)) {
if (c == InternalCodeChar && !invisible) {
const char *t = s + 1;
while (isdigitByte(*t))
@@ -1527,7 +1527,7 @@ void extractEmailAddresses(char *line)
char *mark; /* start of current entry */
char quote = 0, c;
- for (s = t = mark = line; c = *s; ++s) {
+ for (s = t = mark = line; (c = *s); ++s) {
if (c == ',' && !quote) {
mark = t + 1;
c = ' ';
@@ -1571,7 +1571,7 @@ append:
*t = 0;
spaceCrunch(line, eb_true, eb_false);
- for (s = line; c = *s; ++s)
+ for (s = line; (c = *s); ++s)
if (c == ' ')
*s = ',';
if (*line)
diff --git a/src/html.cpp b/src/html.cpp
index 7c7abf6..8556bd9 100644
--- a/src/html.cpp
+++ b/src/html.cpp
@@ -357,7 +357,7 @@ static void get_js_events(void)
int action = topTag->action;
int itype = topTag->itype;
- for (j = 0; t = handlers[j]; ++j)
+ for (j = 0; (t = handlers[j]); ++j)
get_js_event(t);
if (!topTag->jv)
@@ -624,7 +624,7 @@ static void htmlForm(void)
nzFree(a);
}
- if (a = topTag->href) {
+ if ((a = topTag->href)) {
const char *prot = getProtURL(a);
if (prot) {
if (stringEqualCI(prot, "mailto"))
@@ -1364,7 +1364,7 @@ execute:
w = "script";
if (jsrc) {
establish_property_string(obj, "data", jtext, eb_true);
- if (w = strrchr(jsrc, '/')) {
+ if ((w = strrchr(jsrc, '/'))) {
/* Trailing slash doesn't count */
if (w[1] == 0 && w > jsrc)
for (--w; w >= jsrc && *w != '/'; --w) ;
@@ -1451,7 +1451,7 @@ static char *encodeTags(char *html)
basehref = t->href;
top:
- while (c = *h) {
+ while ((c = *h)) {
if (c != '<') {
if (c == '\n')
++ln; /* keep track of line numbers */
@@ -2193,7 +2193,7 @@ unparen:
/* I'm going to assume that if the web designer took the time
* to put in an alt tag, then it's worth reading.
* You can turn this feature off, but I don't think you'd want to. */
- if (a = htmlAttrVal(topAttrib, "alt")) {
+ if ((a = htmlAttrVal(topAttrib, "alt"))) {
s = altText(a);
nzFree(a);
a = NULL;
diff --git a/src/http.c b/src/http.c
index 148517c..93a5746 100644
--- a/src/http.c
+++ b/src/http.c
@@ -116,7 +116,7 @@ char *extractHeaderParam(const char *str, const char *item)
const char *s = str;
/* ; denotes the next param */
/* Even the first param has to be preceeded by ; */
- while (s = strchr(s, ';')) {
+ while ((s = strchr(s, ';'))) {
while (*s && (*s == ';' || (uchar) * s <= ' '))
s++;
if (!memEqualCI(s, item, le))
@@ -470,7 +470,7 @@ eb_bool httpConnect(const char *from, const char *url)
stringEqualCI(prot, "ftps") ||
stringEqualCI(prot, "tftp") || stringEqualCI(prot, "sftp")) {
return ftpConnect(url, user, pass);
- } else if (mt = findMimeByProtocol(prot)) {
+ } else if ((mt = findMimeByProtocol(prot))) {
mimeProcess:
cmd = pluginCommand(mt, url, 0);
/* Stop ignoring SIGPIPE for the duration of system(): */
@@ -840,7 +840,7 @@ static void ftpls(char *line)
stringAndString(&serverData, &serverDataLen, line);
} else {
char c, *q;
- for (q = line; c = *q; ++q) {
+ for (q = line; (c = *q); ++q) {
char *meta = 0;
if (c == '<')
meta = "<";
@@ -1094,7 +1094,7 @@ void allIPs(void)
findField(p, ftype, j, &nf, 0, &tagno, &href, 0);
if (!href)
continue;
- if (dom = getHostURL(href)) {
+ if ((dom = getHostURL(href))) {
/* Ok, many times the same domain will be referenced over and over again.
* A waste of time to look it up over and over again.
* So I check for it here. But what am I missing?
diff --git a/src/jsdom.cpp b/src/jsdom.cpp
index 62ef7d6..eb5ecf0 100644
--- a/src/jsdom.cpp
+++ b/src/jsdom.cpp
@@ -1326,7 +1326,7 @@ void domLink(const char *classname, /* instantiate this class */
const char *htmlclass = topTag->classname;
/* find the class */
- for (i = 0; cp = domClasses[i].obj_class; ++i)
+ for (i = 0; (cp = domClasses[i].obj_class); ++i)
if (stringEqual(cp->name, classname))
break;
diff --git a/src/jsloc.cpp b/src/jsloc.cpp
index 406e8a6..c252159 100644
--- a/src/jsloc.cpp
+++ b/src/jsloc.cpp
@@ -521,7 +521,7 @@ url_initialize(JS::Handle < JSObject * >uo, const char *url, eb_bool readonly,
loc_def_set(uo, "href", url, setter_loc_href, attr);
/* Now make a property for each piece of the url. */
- if (s = getProtURL(url)) {
+ if ((s = getProtURL(url))) {
sprintf(urlbuffer, "%s:", s);
if (strlen(urlbuffer) >= sizeof(urlbuffer))
i_printfExit(MSG_ProtTooLong);
@@ -699,7 +699,7 @@ getter_cookie(JSContext * cx, JS::Handle < JSObject * >obj,
if (memEqualCI(cook, "cookie: ", 8)) { /* should often happen */
strmove(cook, cook + 8);
}
- if (s = strstr(cook, "\r\n"))
+ if ((s = strstr(cook, "\r\n")))
*s = 0;
}
diff --git a/src/main.c b/src/main.c
index a889316..5efe58e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1405,7 +1405,7 @@ eb_bool runEbFunction(const char *line)
}
argl[0] = argtl;
- while (code = *ip) {
+ while ((code = *ip)) {
if (intFlag) {
setError(MSG_Interrupted);
goto fail;
diff --git a/src/sendmail.c b/src/sendmail.c
index 9ff87d6..527acc5 100644
--- a/src/sendmail.c
+++ b/src/sendmail.c
@@ -888,7 +888,7 @@ sendMail(int account, const char **recipients, const char *body,
return eb_false;
/* set copy flags */
- for (j = 0; s = recipients[j]; ++j) {
+ for (j = 0; (s = recipients[j]); ++j) {
char cc = 0;
if (*s == '^' || *s == '?')
cc = *s++;
@@ -901,7 +901,7 @@ sendMail(int account, const char **recipients, const char *body,
}
/* Look up aliases in the address book */
- for (j = 0; s = recipients[j]; ++j) {
+ for (j = 0; (s = recipients[j]); ++j) {
if (strchr(s, '@'))
continue;
t = 0;
@@ -933,7 +933,7 @@ sendMail(int account, const char **recipients, const char *body,
}
/* verify attachments are readable */
- for (j = 0; s = attachments[j]; ++j) {
+ for (j = 0; (s = attachments[j]); ++j) {
if (!ismc && (cx = stringIsNum(s)) >= 0) {
if (!cxCompare(cx) || !cxActive(cx))
return eb_false;
@@ -969,7 +969,7 @@ sendMail(int account, const char **recipients, const char *body,
out = initString(&j);
firstrec = eb_true;
- for (i = 0; s = recipients[i]; ++i) {
+ for (i = 0; (s = recipients[i]); ++i) {
if (reccc[i])
continue;
stringAndString(&out, &j, firstrec ? "To:" : ",\r\n ");
@@ -980,7 +980,7 @@ sendMail(int account, const char **recipients, const char *body,
stringAndString(&out, &j, eol);
firstrec = eb_true;
- for (i = 0; s = recipients[i]; ++i) {
+ for (i = 0; (s = recipients[i]); ++i) {
if (reccc[i] != '^')
continue;
stringAndString(&out, &j, firstrec ? "CC:" : ",\r\n ");
@@ -991,7 +991,7 @@ sendMail(int account, const char **recipients, const char *body,
stringAndString(&out, &j, eol);
firstrec = eb_true;
- for (i = 0; s = recipients[i]; ++i) {
+ for (i = 0; (s = recipients[i]); ++i) {
if (reccc[i] != '?')
continue;
stringAndString(&out, &j, firstrec ? "BCC:" : ",\r\n ");
@@ -1056,7 +1056,7 @@ this format, some or all of this message may not be legible.\r\n\r\n--");
encoded = 0;
if (mustmime) {
- for (i = 0; s = attachments[i]; ++i) {
+ for (i = 0; (s = attachments[i]); ++i) {
if (!encodeAttachment
(s, 0, eb_false, &ct, &ce, &encoded))
return eb_false;
diff --git a/src/stringfile.c b/src/stringfile.c
index fde9de4..dc60d91 100644
--- a/src/stringfile.c
+++ b/src/stringfile.c
@@ -121,7 +121,7 @@ void spaceCrunch(char *s, eb_bool onespace, eb_bool unprint)
int i, j;
char c;
eb_bool space = eb_true;
- for (i = j = 0; c = s[i]; ++i) {
+ for (i = j = 0; (c = s[i]); ++i) {
if (isspaceByte(c)) {
if (!onespace)
continue;
@@ -401,7 +401,7 @@ eb_bool isSQL(const char *s)
if (!isalphaByte(c))
goto no;
- for (++s; c = *s; ++s) {
+ for (++s; (c = *s); ++s) {
if (c == '_')
continue;
if (isalnumByte(c))
@@ -758,7 +758,7 @@ void caseShift(char *s, char action)
int mc = 0;
eb_bool ws = eb_true;
- for (; c = *s; ++s) {
+ for (; (c = *s); ++s) {
if (action == 'u') {
if (isalphaByte(c))
*s = toupper(c);
@@ -1053,7 +1053,7 @@ char *nextScanFile(const char *base)
return s;
} /* end loop over files in directory */
#else
- while (de = readdir(df)) {
+ while ((de = readdir(df))) {
if (de->d_ino == 0)
continue;
if (de->d_name[0] == '.') {
@@ -1087,7 +1087,7 @@ eb_bool sortedDirList(const char *dir, struct lineMap **map_p, int *count_p)
cap = 128;
map = t = allocZeroMem(cap * LMSIZE);
- while (f = nextScanFile(dir)) {
+ while ((f = nextScanFile(dir))) {
if (linecount == cap) {
cap *= 2;
map = reallocMem(map, cap * LMSIZE);
@@ -1215,7 +1215,7 @@ eb_bool envFile(const char *line, const char **expanded)
t = re;
*t++ = '^';
cc = badBrackets = eb_false;
- while (c = *s) {
+ while ((c = *s)) {
if (t >= re + sizeof(re) - 3) {
setError(MSG_ShellPatternLong);
return eb_false;
@@ -1267,7 +1267,7 @@ eb_bool envFile(const char *line, const char **expanded)
else
basedir = line1;
}
- while (file = nextScanFile(basedir)) {
+ while ((file = nextScanFile(basedir))) {
if (filecount > 1)
continue;
re_count =
diff --git a/src/url.c b/src/url.c
index 492913a..c7d59dd 100644
--- a/src/url.c
+++ b/src/url.c
@@ -61,7 +61,7 @@ void unpercentURL(char *url)
char c, *u, *w;
int n;
u = w = url;
- while (c = *u) {
+ while ((c = *u)) {
++u;
if (c == '%' && isxdigit(u[0]) && isxdigit(u[1])) {
c = fromHex(u[0], u[1]);
@@ -232,7 +232,7 @@ static int parseURL(const char *url, const char **proto, int *prlen, const char
if (a < 0)
return eb_false;
- if (free_syntax = protocols[a].free_syntax) {
+ if ((free_syntax = protocols[a].free_syntax)) {
if (data)
*data = p;
if (dalen)
@@ -628,7 +628,7 @@ out_n:
goto out_n;
}
if (rel[0] == '/' && rel[1] == '/') {
- if (s = strstr(base, "//")) {
+ if ((s = strstr(base, "//"))) {
strncpy(n, base, s - base);
n[s - base] = 0;
} else
@@ -810,7 +810,7 @@ char *encodePostData(const char *s)
if (s == EMPTYSTRING)
return EMPTYSTRING;
post = initString(&l);
- while (c = *s++) {
+ while ((c = *s++)) {
if (isalnumByte(c))
goto putc;
if (c == ' ') {
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2014-08-08 11:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-08 11:08 [Edbrowse-dev] [patch] Parenthesize assignments used as a truth value Paul Onyschuk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).