3 ms·
I'm assuming this bug is an instance of a more general one, where people write if(... = ...) when they meant to use == instead? Hence, here, error-handling cod
by henning 18y ago
I'm assuming this bug is an instance of a more general one, where people write if(... = ...) when they meant to use == instead?
Hence, here, error-handling code will be improperly invoked irrespective of whether they get a given error code or not.
- davidw 18y ago> I'm assuming this bug is an instance of a more general one Anyone want to work on a regexp for the more general condition?
- brianr 18y agoMost of these don't look like bugs, but here's a search to match "if (... = ": http://www.google.com/codesearch?hl=en&lr=&q=if\+\ http://www.google.com/codesearch?hl=en&lr=&q=if\+\(\w%2B\+%3D\+&sbtn=Search Can anyone think of a better way to match the subset that are more likely to be bugs?
- alecco 18y agohttp://www.google.com/codesearch?hl=en&lr=&q=if\+\ http://www.google.com/codesearch?hl=en&lr=&q=if\+\(\w%2B\+%3D\+[^(\.]%2B\+%3F\)&sbtn=Search That takes out parentheses (for function calls) and structure member assignment because it might be two statements in one line (ugly and error prone as output will be exactly the same for a = b.c; if(a) {}; vs. if (a=b.c)
- DougBTX 18y ago> whether they get a given error code or not. Helpfully, the Emacs code is commented, which helps explain the pattern: if (errno = ack.hf_retcode) /* set errno based on returned */ return (-1); /* code, if 0, then no error */ Presumably errno is a global, and when it is set to a value other than zero, the function returns. So, it isn't an example of = being used in place of ==, at least this snippet appears to be correct.