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 - SDL_GL_GetProcAddress returns NON-null pointer for invalid string
Summary: SDL_GL_GetProcAddress returns NON-null pointer for invalid string
Status: RESOLVED INVALID
Alias: None
Product: SDL
Classification: Unclassified
Component: *don't know* (show other bugs)
Version: 1.2.15
Hardware: x86_64 Linux
: P2 normal
Assignee: Ryan C. Gordon
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-12-31 18:23 UTC by danhath
Modified: 2014-01-03 20:45 UTC (History)
0 users

See Also:


Attachments
Prints invalid function pointer from SDL_GL_GetProcAddress (1.09 KB, text/x-c++src)
2013-12-31 18:23 UTC, danhath
Details

Note You need to log in before you can comment on or make changes to this bug.
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.