glx: createcontext: silence analyzer warning and make code easier to understand
This warning is probably a false alarm, but it's trivial to fix.
| ../glx/createcontext.c: In function ‘__glXDisp_CreateContextAttribsARB’:
| ../glx/createcontext.c:172:24: warning: dereference of NULL ‘0’ [CWE-476] [-Wanalyzer-null-dereference]
|   172 |         switch (attribs[i * 2]) {
|       |                 ~~~~~~~^~~~~~~
The situation is too complex for the analyzer to handle:
(but also not immediately clear for the human reader)
* `attribs` is only NULL when req->numAttribs is 0
* in that case, the for loop is no-op, so `attribs` won't ever be deref'ed.
We can make it easier for both analyzer as well as human reader by just putting
the whole loop into an `if (req->numAttribs)` and assigning it inside there.
There shouldn't be any (practically measurable) extra cost.
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
			
			
This commit is contained in:
		
							parent
							
								
									2b3bbce30b
								
							
						
					
					
						commit
						9ee96639d7
					
				| 
						 | 
				
			
			@ -80,8 +80,6 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
 | 
			
		|||
{
 | 
			
		||||
    ClientPtr client = cl->client;
 | 
			
		||||
    xGLXCreateContextAttribsARBReq *req = (xGLXCreateContextAttribsARBReq *) pc;
 | 
			
		||||
    int32_t *attribs = (req->numAttribs != 0) ? (int32_t *) (req + 1) : NULL;
 | 
			
		||||
    unsigned i;
 | 
			
		||||
    int major_version = 1;
 | 
			
		||||
    int minor_version = 0;
 | 
			
		||||
    uint32_t flags = 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -168,7 +166,11 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
 | 
			
		|||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (i = 0; i < req->numAttribs; i++) {
 | 
			
		||||
    int32_t *attribs = NULL;
 | 
			
		||||
 | 
			
		||||
    if (req->numAttribs) {
 | 
			
		||||
        attribs = (int32_t *) (req + 1);
 | 
			
		||||
        for (int i = 0; i < req->numAttribs; i++) {
 | 
			
		||||
            switch (attribs[i * 2]) {
 | 
			
		||||
            case GLX_CONTEXT_MAJOR_VERSION_ARB:
 | 
			
		||||
                major_version = attribs[2 * i + 1];
 | 
			
		||||
| 
						 | 
				
			
			@ -198,7 +200,6 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
 | 
			
		|||
                if (reset != GLX_NO_RESET_NOTIFICATION_ARB
 | 
			
		||||
                    && reset != GLX_LOSE_CONTEXT_ON_RESET_ARB)
 | 
			
		||||
                    return BadValue;
 | 
			
		||||
 | 
			
		||||
                break;
 | 
			
		||||
 | 
			
		||||
            case GLX_CONTEXT_RELEASE_BEHAVIOR_ARB:
 | 
			
		||||
| 
						 | 
				
			
			@ -227,6 +228,7 @@ __glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
 | 
			
		|||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* The GLX_ARB_create_context spec says:
 | 
			
		||||
     *
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue