News for hackers. Stuff that matters.
Re:How to find size of an array in C without sizeof by quotemstr on Monday December 26, 2016 @04:35PM (#13259886)
The "how likely is it, really?" response to questions of technical correctness has always bothered me. It takes a mindset completely alien to mine to say "Here's a race condition. Sure, it's undefined behavior, but the race is narrow, so it's rare" or to say "Sure, memory allocation can theoretically fail, but in practice almost never does" or to say "fsync is too slow and most computers have batteries these days".

Software is unreliable enough as it is due to problems beneath our notice. It seems reckless to avoid fixing problems that we do notice. Sure, you could argue that rare problems are rare and that users probably won't notice them --- this attitude is penny-wise and pound-foolish, because you can't meaningfully reason about a system that's only probably correct.

Re:How to find size of an array in C without sizeof by Swizec on Monday December 26, 2016 @04:49PM (#13259945)
Engineering is about tradeoffs. How many once-in-a-thousand bugs do you fix before you tackle the one-in-a-million? Or one in a billion? What about if it takes $10/bug to fix every 1:1000 bug and $100,000 to fix one 1:1000000 bug?

Correctness is great in theory, but in practice it's a matter of what's important.

Re:How to find size of an array in C without sizeof by mannykannot on Monday December 26, 2016 @07:44PM (#13260584)
If you are only looking at probability and cost-to-fix you are overlooking something important - the cost if/when it happens.
Re:How to find size of an array in C without sizeof by verdax_1 on Tuesday December 27, 2016 @02:43AM (#13261846)
This is really emphasized in things like dmfea and other failure mode analysis documents or regulated industry. They want you to document the likelihood, your ability to recover from the failure, as well as the cost o the failure. You can say that you didn't want to pay for someone fixing some unlikely fail mode but that's small consultation to the people whose lives your product is ruining.
Re:How to find size of an array in C without sizeof by mjburgess on Monday December 26, 2016 @04:40PM (#13259902)
The problem you're latching on to I think is how the context for caculating a probability can vary.

If it were really as likely as, say, the sun exploding that X happened then it would be of no use to expend time on X.

BUT very often people speaking about the probability of events given suspicious constraints. While a memory allocation might not fail in most situations it will fail often in some situations. And a one-in-a-million chance is almost guaranteed when there are millions of uses.

Re:How to find size of an array in C without sizeof by verdax_1 on Tuesday December 27, 2016 @02:26AM (#13261790)
Also worth considering that our processors are handling billions of ops per second. One in a million might be happening all the time even for one user.
Re:How to find size of an array in C without sizeof by spdionis on Monday December 26, 2016 @04:51PM (#13259957)
That's why it's called one in a million...
Re:How to find size of an array in C without sizeof by maxlybbert on Monday December 26, 2016 @10:25PM (#13261095)
Re:How to find size of an array in C without sizeof by tholmes on Monday December 26, 2016 @07:31PM (#13260533)
One in a million happens quite often if you're processing something like ~100k requests a second.
Re:How to find size of an array in C without sizeof by spdionis on Tuesday December 27, 2016 @04:09AM (#13262112)
In fact I agreed with the parent and just posted a tongue in cheek remark.

One in a million literally means that at ~100k requests a second it will happen once every 10 seconds.

Re:How to find size of an array in C without sizeof by jschwartzi on Monday December 26, 2016 @09:03PM (#13260820)
But it's extremely unlikely when you're processing 10 requests a week, such as might be the case for the web server in a consumer-grade router.
Re:How to find size of an array in C without sizeof by quotemstr on Monday December 26, 2016 @09:45PM (#13260953)
It's amazing how skilled blackhats are at converting "rare bug that doesn't affect the UI" into "massive DDoS cannon".
Re:How to find size of an array in C without sizeof by jschwartzi on Tuesday December 27, 2016 @12:52AM (#13261541)
And you can see how risk analyses by senior engineers with tons of embedded experience who are used to working with systems that are not networked leads to problems when their systems are later networked.
Re:How to find size of an array in C without sizeof by paulddraper on Monday December 26, 2016 @09:34PM (#13260918)
...by hundreds of thousands of customers.
Re:How to find size of an array in C without sizeof by chongli on Tuesday December 27, 2016 @10:09AM (#13263513)
One in a million isn't just a typical statement of probability, it's a colloquialism used to refer to things that never happen in practice. It's highly misleading to use in the context of computers which, due to their natures, have one in a million events occurring constantly.
Re:How to find size of an array in C without sizeof by spdionis on Tuesday December 27, 2016 @10:28AM (#13263644)
My comment was tongue in cheek.
Re:How to find size of an array in C without sizeof by Dylan16807 on Monday December 26, 2016 @11:22PM (#13261260)
>he "how likely is it, really?" response to questions of technical correctness has always bothered me.

But the question is important in another context: language design. Why is this undefined behavior something that exists in the first place? Objects larger than PTRDIFF_MAX could just not be allowed! This avoids the problem and makes code easier to reason about, with pretty much no downside.

Re:How to find size of an array in C without sizeof by verdax_1 on Tuesday December 27, 2016 @02:32AM (#13261808)
I like the way you're thinking, but that sort of thing probably doesn't get past a committee. "Hey we might not be able to think of an application but that doesn't mean our users won't have a legitimate reason for doing it ... Motion passed."