Fixed bug 3720 - SDL_GL_GetAttribute doesn't check for initialized video driver
authorSam Lantinga <slouken@libsdl.org>
Mon, 31 Jul 2017 12:57:15 -0700
changeset 111716f6e8880cd37
parent 11170 b5fe34e8401f
child 11172 879cacfe85c2
Fixed bug 3720 - SDL_GL_GetAttribute doesn't check for initialized video driver

Simon Hug

SDL_GL_GetAttribute doesn't check if a video driver has been initialized and will access the SDL_VideoDevice pointer, which is NULL at that point.

I think all of the attributes require an initialized driver, so a simple NULL check should fix it. Patch is attached.
include/SDL_video.h
src/video/SDL_video.c
     1.1 --- a/include/SDL_video.h	Sun Jul 30 14:36:01 2017 -0400
     1.2 +++ b/include/SDL_video.h	Mon Jul 31 12:57:15 2017 -0700
     1.3 @@ -1111,11 +1111,16 @@
     1.4  
     1.5  /**
     1.6   *  \brief Set an OpenGL window attribute before window creation.
     1.7 + *
     1.8 + *  \return 0 on success, or -1 if the attribute could not be set.
     1.9   */
    1.10  extern DECLSPEC int SDLCALL SDL_GL_SetAttribute(SDL_GLattr attr, int value);
    1.11  
    1.12  /**
    1.13   *  \brief Get the actual value for an attribute from the current context.
    1.14 + *
    1.15 + *  \return 0 on success, or -1 if the attribute could not be retrieved.
    1.16 + *          The integer at \c value will be modified in either case.
    1.17   */
    1.18  extern DECLSPEC int SDLCALL SDL_GL_GetAttribute(SDL_GLattr attr, int *value);
    1.19  
     2.1 --- a/src/video/SDL_video.c	Sun Jul 30 14:36:01 2017 -0400
     2.2 +++ b/src/video/SDL_video.c	Mon Jul 31 12:57:15 2017 -0700
     2.3 @@ -3113,9 +3113,17 @@
     2.4      GLenum attachmentattrib = 0;
     2.5  #endif
     2.6  
     2.7 +    if (!value) {
     2.8 +        return SDL_InvalidParamError("value");
     2.9 +    }
    2.10 +
    2.11      /* Clear value in any case */
    2.12      *value = 0;
    2.13  
    2.14 +    if (!_this) {
    2.15 +        return SDL_UninitializedVideo();
    2.16 +    }
    2.17 +
    2.18      switch (attr) {
    2.19      case SDL_GL_RED_SIZE:
    2.20  #if SDL_VIDEO_OPENGL