Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Sanity Check for malloc() in catch.hpp #610

Closed
dogbert2 opened this issue Mar 14, 2016 · 6 comments
Closed

Missing Sanity Check for malloc() in catch.hpp #610

dogbert2 opened this issue Mar 14, 2016 · 6 comments

Comments

@dogbert2
Copy link

Missing Sanity Check for malloc() in catch.hpp

There appears to be a missing sanity check for malloc in directory
'src/catch', file 'catch.hpp' as the code segment below shows:

inline size_t registerTestMethods() {
    size_t noTestMethods = 0;
    int noClasses = objc_getClassList( CATCH_NULL, 0 );

    Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses);
    objc_getClassList( classes, noClasses );
@nabijaczleweli
Copy link
Contributor

What kind of a "sanity check"? All multiplications/length seem to be correct.
Well, using malloc() is a questionable matter in and of itself.

@refi64
Copy link

refi64 commented Mar 14, 2016

@nabijaczleweli malloc returning NULL.

@refi64
Copy link

refi64 commented Mar 14, 2016

Though this really should be classes = new Class[noClasses]...

@nabijaczleweli
Copy link
Contributor

This should be a smart pointer :v
Or, rather, an actual container

@philsquared
Copy link
Collaborator

@dogbert2 - you are technically correct (which is the best kind of correct). However I don't think it's a big deal here. This is called immediately on entering main() - and there's nothing you can do to recover from it. If you're out of memory for this call then the changes of something like iostreams working is pretty low too.

@kirbyfan64 and @nabijaczleweli bear in mind this is Objective-C code (well, technically it's C code in an Objective-C context, reflecting over Objective-C code). That memory handling needs to interact with ARC (Automatic Reference Counting) - and also stick around for the lifetime of the program since instances of the Class object are kept around. I'm sure it could be cleaned up but it's tricky stuff that's been "just working" for years now without any need to touch it.

@horenmar
Copy link
Member

I agree with Phil here, if things went wrong so soon, then there is nothing to do, except maybe explicitly exit.

@horenmar horenmar added Resolved - pending review Issue waiting for feedback from the original author Won't Fix labels Mar 3, 2017
@horenmar horenmar removed the Resolved - pending review Issue waiting for feedback from the original author label Mar 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants