4 ms·
The error is here: https://github.com/zcoinofficial/zcoin/blob/81a667867b5d84893e4c225a8d73eddd78ac16c2/src/main.cpp#L963 https://github.com/zcoinofficial/zcoi
by WalterBright 10y ago
The error is here:
https://github.com/zcoinofficial/zcoin/blob/81a667867b5d84893e4c225a8d73eddd78ac16c2/src/main.cpp#L963 https://github.com/zcoinofficial/zcoin/blob/81a667867b5d8489...
and the line of code:
zccoinSpend.denomination == libzerocoin::ZQ_LOVELACE;
In other words, a statement with no effect. In D, such a line gives an error, not a warning:
Error: == has no effect in expression
You can force the statement to be accepted by casting it to void.
It's really past time for languages to not accept such code any more. Legacy code needs to get fixed.
- Strom 10y agoAny C++ static analyzer worth its salt would catch this. I don't think this is so much of a C++ language issue, but more of an issue with C++ environments/compilers not doing static analyzing by default, and/or the authors of this software not being aware of the fact that they need to use static analyzers.
- WalterBright 10y agoYou're right. My contention is that the language itself should no longer accept such code, it shouldn't be relegated to an ignorable warning or a 3rd party tool that isn't run.
- Strom 10y agoYes, major improvements could be made by changing the defaults of the tools that beginners use. I edited my original comment to be more clear on this as well.
- WalterBright 10y agoI think we're going to have to disagree. It isn't just an issue for beginner code. Experts make such mistakes, too. Expecting them to not make mistakes is unrealistic, and sending them back for more training isn't going to work, either. I can't think of a reason any modern language should accept such code. If you're interested, I recommend the series "Air Disasters" on TV. Each episode analyzes one crash, where investigators determine the cause of the accident, and what the corrective action should be taken. Often, it comes down to "how could a pilot with 10,000 hours experience make such a mistake". While it would be easy for investigators to blame the pilot, often they find that the mistake was just too easy to make, and they recommend changing the design or procedures or both.
- gpawl 10y agoI think strom meant that beginners don't know to turn on -Wall -Werror and friends
- gpawl 10y agoIndeed, the next standard should ban such things, and modern compilers should reject these patterns by default, unless a --legacy_security_unsage flag is set.
- WalterBright 10y agoPerhaps the switch should be named: --accept_my_buggy_stupid_code so nobody is going to type that in by accident, and nobody is going to want to defend it in the code review process. And the compiler vendor will still get a gold star for being 100% language compliant :-)
- jacquesm 10y agoYou're absolutely right (to my surprise), it gives: test.cpp: In function ‘int main()’: test.cpp:13:11: warning: statement has no effect [-Wunused-value] a == b; ^ But only after enabling a warning that is not on by default. -Wall and -Werror should be the default.
- WalterBright 10y agoIt should be an error, not a warning (default or not). There are a number of things like this that should just not be accepted anymore. Here's another one: if (condition); dothis(); No compiler should accept that, regardless of switch settings.
- jacquesm 10y agoFully agreed. There is absolutely no way that is something a programmer ever intended. In fact I think that just if (condition); Should already be enough to trigger the error. (Any 'if' statement without a body).
- spacemanmatt 10y agoThere could be an important side-effect in condition. Isn't persistent state fun!?
- hasenj 10y agoIn that case an empty curly block would make the intention explicit.
- jacquesm 10y agoThat could still be a case of a dropped line in the body.
- shawabawa3 10y agoWhy have it in an if though?
- gpawl 10y agoHow is D holding up against newer upstarts like Go and Rust? It seems that D never really got the love it deserved, perhaps because it didn't have a Google or Mozilla behind it.
- WalterBright 10y agoOur user base is steadily growing. Coming soon is a nice upgrade to the language designed to eliminate stray pointers into expired stack frames. I feel it is my duty as a language designer to make it hard for programmers to commit common bugs. It's just too expensive for companies to ship these kinds of things.
- electrum 10y agoThe commit that fixes it does not change any tests: https://github.com/zcoinofficial/zcoin/commit/0359bcb2ead7feac5a3a5f6c6581b1b54cda8dd1 https://github.com/zcoinofficial/zcoin/commit/0359bcb2ead7fe... This indicates that the code in question is not covered by tests. I work on a database, for which correctness is paramount, so it's unnerving to see any code fixes not associated with test additions or changes. I would have thought that cryptocurrency had similar standards.
- WalterBright 10y agoWe've modified the dlang Github tester to run coverage tests over Pull Requests, and uncovered changes get marked with a scarlet bar. While some changes can't be tested with a test suite, the result has been a marked improvement in the quality of pull requests (including mine) because it is embarrassing to submit untested code.
- unbeli 10y agoI think that won't even compile due to an accidentally pasted URL here: https://github.com/zcoinofficial/zcoin/commit/0359bcb2ead7feac5a3a5f6c6581b1b54cda8dd1#diff-7ec3c68a81efff79b6ca22ac1f1eabbaR775 https://github.com/zcoinofficial/zcoin/commit/0359bcb2ead7fe...
- iMerNibor 10y agoShould compile fine, it'll just evaluate to a goto label named "https" and a comment after
- JoachimSchipper 10y agogcc doesn't accept that if you enable some warnings and -Werror. I agree that the default is bad, though.
- WalterBright 10y agoThe language still accepts it, though.
- barking 10y agoSorry if this is stating the obvious. I'm guessing that this was meant to be a single equals sign for an assignment rather than a double equals for an equality test?
- maccard 10y agoI'm not advocating writing any code like this, but you can have an overloaded == operator that _does_ have side effects, e.g. [0] [0] https://ideone.com/eJgiN9 https://ideone.com/eJgiN9
- Sanddancer 10y agoIt gets more fun when you're dealing with things like memory mapped I/O, where reading from a register is a destructive action, so even a non-overloaded == can cause side effects.
- WalterBright 10y agoThat's what volatile reads are for - they indicate a side effect.
- phaylon 10y agoThe D forums seem to suggest this is only true for primitive types, is that correct?