Closed Bug 1285918 Opened 8 years ago Closed 8 years ago

Analysis to produce an error when having operator new overloaded by a class with macro like NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW

Categories

(Developer Infrastructure :: Source Code Analysis, defect)

defect
Not set
normal

Tracking

(firefox50 affected)

RESOLVED WONTFIX
Tracking Status
firefox50 --- affected

People

(Reporter: andi, Assigned: andi)

References

Details

Attachments

(1 file)

As we've discussed at our London All Hands Meeting we shouldn't allow in our code the overload operator new in different classes, so we must have a checker in our static analysis tool that checks this and if asserts true it should return a compile error.
Summary: Analysis to produce an error when having operator new overloaded by a class → Analysis to produce an error when having operator new overloaded by a class with macro NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
To be more specific, this should be true only a default implementation for new operator is present like in case of macro: NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
Summary: Analysis to produce an error when having operator new overloaded by a class with macro NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW → Analysis to produce an error when having operator new overloaded by a class with macro like NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
What we want to avoid with this checker is the usage of declarations like: >> void* operator new(size_t sz) CPP_THROW_NEW { >> void* rv = ::operator new(sz); >> if (rv) { >> memset(rv, 0, sz); >> } >> return rv; >> } This kind of overloading of operator new shouldn't be allowed to exist in our code.
Attachment #8770110 - Flags: feedback?(amarchesini)
https://reviewboard.mozilla.org/r/63684/#review61210 Lgtm. But, is this what we decided during the meeting? If I remember correctly, the idea was to get rid of |operation new()| in our code base for member initialization. We can use part of this code to avoid the use of such operator. And in the meantime we can remove macro: NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
Attachment #8770110 - Flags: feedback?(amarchesini)
what do you think Ehsan, should we have a checker like this one? I know that is we eliminate macro NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW this would become a false problem but still we can prevent this from ever happening.
Flags: needinfo?(ehsan)
Apologies for the long delay guys, I've been on vacation/sick after London... I find it hard to justify banning this construct altogether, since it may have legitimate use cases that we're not currently aware of. I think for the purpose of member initialization, removing NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW and replacing its usages with normal initialization should be all that we need to do.
Status: NEW → RESOLVED
Closed: 8 years ago
Flags: needinfo?(ehsan)
Resolution: --- → WONTFIX
Product: Core → Firefox Build System
Product: Firefox Build System → Developer Infrastructure
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: