Giter Club home page Giter Club logo

Comments (8)

GoogleCodeExporter avatar GoogleCodeExporter commented on June 22, 2024
Ugg, sorry:

f = NULL;

No dereference.  my bad.

Original comment by [email protected] on 20 Aug 2009 at 7:21

from mp4v2.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 22, 2024
Whoa. That's wrong in so many ways.

As stated by point #3 you desire MP4FileHandle hFile to be set to NULL after 
object is destroyed.
That is not possible as hFile must be MP4FileHandle* in order to accomplish the 
enhancement you desire.
In case it was changed, then yes a simple "*hFile = NULL" would be your 
enhancement.
Unfortunately this will break all existing MP4Close() usage.

Secondly, it is illegal to assign NULL to an object, which 'f' represents. The 
reason why you do not get a 
compiler error is because MP4File(int) constructor accepts an integer. In my 
opinion it would be best to 
change MP4File(int) --> "explicit MP4File(int)" to avoid implicit conversion of 
NULL to a new object.

"f = NULL;" does the following which I'm sure is not desired:

1. create a temporary MP4File object by using constructor MP4File(int) which 
allows NULL to be used as per 
not perfectly clear C++ standard.
2. assign the tmp object to f (this uses default object copy semantics because 
there is no custom defined 
copy constructor)
3. this behavior would be undefined because 'f' was just deleted. while it 
might not generate a coredump, 
because the memory is most likely still available, it's certainly undefined to 
use a dead object with copy 
semantics.

Original comment by [email protected] on 15 Sep 2009 at 11:45

from mp4v2.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 22, 2024
Small correction. It's strictly not "illegal" to assign NULL to an object. You 
need help from implicit constructors or 
overloaded assignment operators. In either case though, it's not what you 
desire to do for this issue.

Original comment by [email protected] on 15 Sep 2009 at 11:48

from mp4v2.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 22, 2024
In my haste, I wrote some bad code.  Sorry.  Let me explain myself better.

Here is the specific function:

    void MP4Close(MP4FileHandle hFile)
    {
        if( !MP4_IS_VALID_FILE_HANDLE( hFile ))
            return;

        MP4File& f = *(MP4File*)hFile;
        try {
            f.Close();
        }
        catch ( MP4Error* e ) {
            PRINT_ERROR( e );
            delete e;
        }

        delete &f;
    }

MP4FileHandle is simply a void*:

typedef void*       MP4FileHandle;

...that is, just a pointer.  So the fix should be:

void MP4Close(MP4FileHandle hFile)     
{
...
delete &f;     
hFile = NULL;
} 

In general, when you delete something a pointer points to (and in this case, 
hFile
points to MP4File*), you should also set it to null.  Other places in the 
library do
this consistently, so I don't know why this function wouldn't.

Original comment by [email protected] on 16 Sep 2009 at 12:00

from mp4v2.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 22, 2024
Also, 

"*hFile = NULL"

...would be totally wrong.  This would actually do what you seem to be 
explaining,
which would be setting a class instance to NULL, which yes, I agree is a compile
error.  Again, I apologize for not being clear and posting some bad code, but 
this is
clearly not the point I was trying to make.

But the above change absolutely does not break any MP4Close() usage; it is 
perfectly
legal to NULL out a pointer to an object that has just been deleted.


Original comment by [email protected] on 16 Sep 2009 at 12:07

from mp4v2.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 22, 2024
I'll omit the typedef so you can see what's happening:

void MP4Close( void* pFile ) {
    pFile = NULL; // useless as pFile is an in-parm and would do nothing to set caller's pointer
}

void MP4Close( void** ppFile ) {
   *ppFile = NULL; // sets (out) pFile to NULL
}

And as mentioned earlier, this requires an incompatible change in function 
signature.

Original comment by [email protected] on 16 Sep 2009 at 12:19

from mp4v2.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 22, 2024
Kona,

My apologies, the ** thing always throws me for a loop, but you're definitely 
right.
 And yes, I agree this would be a sizable change that is not worth the effort.  I'll
just null out the argument after I call MP4Close like I'm currently doing.

You can close this--thanks for the help!

Original comment by [email protected] on 16 Sep 2009 at 12:42

from mp4v2.

GoogleCodeExporter avatar GoogleCodeExporter commented on June 22, 2024

Original comment by [email protected] on 22 Nov 2009 at 11:39

  • Changed state: WontFix

from mp4v2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.