I don't really see how std::array is a good thing, to be honest. It seems downright arcane to have to explicitly stuff the size of the array in the type name (maybe std::to_array in C++20 addresses this?). std::begin and std::end work just fine for a C array, so why use std::array? Is there some benefit I'm not seeing?
| From: Greg Thompson Sent: Freitag, 23. August 2019 07:27 To: Chromium-dev Reply To: g...@chromium.org Subject: [chromium-dev] Opinions on std::array? |
Thanks for the feedback. These are great points.Regarding .at(), though, that's not an option for Chromium (or Google) development since it throws exceptions.
On Fri, Aug 23, 2019 at 8:44 AM Jan van Oort <j...@kivu.tech> wrote:
Bounds-checking on access are imho a nice win and can avoid quite some bugs.Jan van Oort
Head of Research
KIVU Technologies GmbH
www.kivu.tech
From: Greg ThompsonSent: Freitag, 23. August 2019 07:27To: Chromium-devReply To: g...@chromium.orgSubject: [chromium-dev] Opinions on std::array?
Hi gang. In a recent CL where I was using a bog-standard C array for some constants. One reviewer asked (paraphrasing) "why aren't you using std::array here?" So I switched to that. Then another reviewer asked (paraphrasing) "what does std::array buy you here?", which I interpreted as "why are you using std::array here?"--I don't really see how std::array is a good thing, to be honest. It seems downright arcane to have to explicitly stuff the size of the array in the type name (maybe std::to_array in C++20 addresses this?). std::begin and std::end work just fine for a C array, so why use std::array? Is there some benefit I'm not seeing?Thanks.
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+unsubscribe@chromium.org.
On Friday, 23 August 2019 18:22:52 UTC+10, Greg Thompson wrote:Thanks for the feedback. These are great points.Regarding .at(), though, that's not an option for Chromium (or Google) development since it throws exceptions..at() is fine to use, it crashes instead of throwing.
On Fri, Aug 23, 2019 at 8:44 AM Jan van Oort <j...@kivu.tech> wrote:
Bounds-checking on access are imho a nice win and can avoid quite some bugs.Jan van Oort
Head of Research
KIVU Technologies GmbH
www.kivu.tech
From: Greg ThompsonSent: Freitag, 23. August 2019 07:27To: Chromium-devReply To: g...@chromium.orgSubject: [chromium-dev] Opinions on std::array?
Hi gang. In a recent CL where I was using a bog-standard C array for some constants. One reviewer asked (paraphrasing) "why aren't you using std::array here?" So I switched to that. Then another reviewer asked (paraphrasing) "what does std::array buy you here?", which I interpreted as "why are you using std::array here?"--I don't really see how std::array is a good thing, to be honest. It seems downright arcane to have to explicitly stuff the size of the array in the type name (maybe std::to_array in C++20 addresses this?). std::begin and std::end work just fine for a C array, so why use std::array? Is there some benefit I'm not seeing?Thanks.
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAKQnr0SbQWZsf7nvKRNBKH%2BeN6xXsZRZc0d9YgyPBge04PeGMw%40mail.gmail.com.
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/4ea3383c-96af-402f-99da-2bc797d1366b%40chromium.org.
You received this message because you are subscribed to a topic in the Google Groups "Chromium-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/a/chromium.org/d/topic/chromium-dev/DcxltYiLPjQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAKQnr0R9Tk%3DH1E-2%2BC4jm8n4pdWLEM1i61QGsc5w7E4qcB8Z1g%40mail.gmail.com.
Is it worth wrapping up this thread with a concise recommendation that we can all follow? For example, prefer .at() over operator[], especially when the index is not obviously correct (e.g., operator[] for a for loop with no subtlety is okay)?
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAOuvq23j2b%3DEGEzVrcw00Yq30%3Db4foHmOHzH-khCbjbE4a56PA%40mail.gmail.com.
+Adrian Taylor has projects to quantify and to illustrate the memory corruption problem, and +Daniel Cheng and I are going to work on raising the What To Do In Base? question in a structured way. Additionally I have a (currently slow-moving) project to bring compile-time-configurable sanity checks (in production) to Abseil and then hopefully libc++, and of course we've been adding such checks to base for a while now.
Sure, and if you can manage to transparently check without an unreasonable perf cost, that will be a useful solution, because it will avoid modifying the apparent intent of code people write. (Whether you will ever be able to do that is another matter. I wish you well. But I think we'd be better served taking the highest-risk surface areas of our code and rewriting them in Rust.)
If I see someone using at(), I assume that either (a) they don't know what they're doing or (b) they have reason to believe that their indexes go out of bounds here. When (b) is not true, the code is misleading. You can argue that my assumptions are bad, but unless we systematically replace [] with .at() throughout the codebase, I don't think they're out of step with what we actually practice. FWIW, I assume similar things when people explicitly use checked numerics, checked casts, etc. -- that they have special reason to believe there is danger in that area that isn't commonly present.
(See also optional::value vs. optional::operator*.)This is actually a great illustrative example. I had no idea that one of those checked and the other didn't -- I thought they were identical. And I'm one of the team style owners and probably more C++-knowledgeable than the median Chrome engineer.It would be nice if all of us could memorize the whole language spec. Unfortunately, C++ is huge, and we are fallible.
On Tue, Aug 27, 2019 at 10:43 AM Peter Kasting <pkas...@chromium.org> wrote:Sure, and if you can manage to transparently check without an unreasonable perf cost, that will be a useful solution, because it will avoid modifying the apparent intent of code people write. (Whether you will ever be able to do that is another matter. I wish you well. But I think we'd be better served taking the highest-risk surface areas of our code and rewriting them in Rust.)Good news! You are not alone in this belief. :)If I see someone using at(), I assume that either (a) they don't know what they're doing or (b) they have reason to believe that their indexes go out of bounds here.
When (b) is not true, the code is misleading. You can argue that my assumptions are bad, but unless we systematically replace [] with .at() throughout the codebase, I don't think they're out of step with what we actually practice. FWIW, I assume similar things when people explicitly use checked numerics, checked casts, etc. -- that they have special reason to believe there is danger in that area that isn't commonly present.I usually find that people were not using checked numerics because they didn't know how bonkers C/C++ integer semantics really are — not because they already thought they had checked enough.Basically, C/C++'s default semantics, across the board, are backwards. Hence Rust and other things.(See also optional::value vs. optional::operator*.)This is actually a great illustrative example. I had no idea that one of those checked and the other didn't -- I thought they were identical. And I'm one of the team style owners and probably more C++-knowledgeable than the median Chrome engineer.It would be nice if all of us could memorize the whole language spec. Unfortunately, C++ is huge, and we are fallible.Even just enumerating C++'s undefined behaviors is an open project. I find that enjoyable*.Anyway, we all agree that we need to make the language-as-used-by-Chromium-developers safe enough for Chromium's users, and Security Team is chugging along on that. Expect more in this space...* "Enjoyable" means "bad" when a security person says it
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAOuvq20zHDa1qFKsA1KFmrZT1V11vTZbTGpbhpwHHbGHqhv%3D9Q%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAP0-Qpt-CFon996Rbqi7H6Ur6m6Cm7hhO25TFAF2VF9d1hW-fA%40mail.gmail.com.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+unsubscribe@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAOuvq20zHDa1qFKsA1KFmrZT1V11vTZbTGpbhpwHHbGHqhv%3D9Q%40mail.gmail.com.
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+unsubscribe@chromium.org.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAOuvq20zHDa1qFKsA1KFmrZT1V11vTZbTGpbhpwHHbGHqhv%3D9Q%40mail.gmail.com.
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
On Tue, Aug 27, 2019 at 10:31 AM Chris Palmer <pal...@chromium.org> wrote:
+Adrian Taylor has projects to quantify and to illustrate the memory corruption problem, and +Daniel Cheng and I are going to work on raising the What To Do In Base? question in a structured way. Additionally I have a (currently slow-moving) project to bring compile-time-configurable sanity checks (in production) to Abseil and then hopefully libc++, and of course we've been adding such checks to base for a while now.
Sure, and if you can manage to transparently check without an unreasonable perf cost, that will be a useful solution, because it will avoid modifying the apparent intent of code people write. (Whether you will ever be able to do that is another matter. I wish you well. But I think we'd be better served taking the highest-risk surface areas of our code and rewriting them in Rust.)
As-is, though, using at() is so rare that it sticks out in a similar way that doing this does:void foo(int* x) {if (!x)return;...This implies to the reader that |x| can be null. If |x| can't be null, this code often misleads other maintainers in the future into inserting unnecessary null checks all over their own code. This is why we discourage "paranoid" checking -- it's not about the perf cost of it, it's about the readability and maintenance cost. Handling DCHECK failure is discouraged for the same reason.
If I see someone using at(), I assume that either (a) they don't know what they're doing or (b) they have reason to believe that their indexes go out of bounds here. When (b) is not true, the code is misleading. You can argue that my assumptions are bad, but unless we systematically replace [] with .at() throughout the codebase, I don't think they're out of step with what we actually practice. FWIW, I assume similar things when people explicitly use checked numerics, checked casts, etc. -- that they have special reason to believe there is danger in that area that isn't commonly present.