We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2331

Summary: SDL_GL_GetProcAddress returns NON-null pointer for invalid string
Product: SDL Reporter: danhath
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 1.2.15   
Hardware: x86_64   
OS: Linux   
Attachments: Prints invalid function pointer from SDL_GL_GetProcAddress

Description danhath 2013-12-31 18:23:19 UTC
Created attachment 1508 [details]
Prints invalid function pointer from SDL_GL_GetProcAddress

The function SDL_GL_GetProcAddress returns NON null function pointers for bogus strings.  For example,

SDL_GL_GetProcAddress("glThisIsNotAnOpenGLFunctionName")

does NOT always return null.  Even if this turns out to not be a problem with SDL but something SDL is using, I would think SDL should guard against this.  An invalid function pointer is a disaster waiting to happen.  This behavior makes me wonder what would happen with a valid OpenGL extension name that is unavailable on some machine.

I have attached a small one file program to reproduce the bug (which happens on my machine).

Thank you.
Comment 1 Ryan C. Gordon 2014-01-02 04:29:14 UTC
Not a bug:
    http://dri.freedesktop.org/wiki/glXGetProcAddressNeverReturnsNULL/

According to OpenGL, it is the application's responsibility to check for available extensions and only call the functions if they really exist. A non-NULL return from GetProcAddress() does not mean the function is safe to call.

We can't catch this in SDL, as a function name that's invalid today may become valid when a new extension is introduced tomorrow.

--ryan.
Comment 2 danhath 2014-01-02 13:56:11 UTC
I see.  Maybe the documentation for SDL_GL_GetProcAddress could be changed to read:

 "Returns a pointer to the named OpenGL function, or returns an undefined value if the function is not found".

 I didn't get burned by this b/c I was just playing around, but I can imagine newcomers not being aware of these misconceptions!

Thanks for your trouble,

-Dan
Comment 3 Ryan C. Gordon 2014-01-03 20:45:43 UTC
(In reply to danhath from comment #2)
> I see.  Maybe the documentation for SDL_GL_GetProcAddress could be changed
> to read:

I've now updated the docs here...

    https://wiki.libsdl.org/SDL_GL_GetProcAddress

...it's actually a complicated and ugly subject, so it turned out to be a couple of paragraphs on how to navigate it.   :)

--ryan.