wmix: do not risk a crash (null-pointer-dereference) if $DISPLAY is not set
The original code merely assumed that an XOpenDisplay failure was caused only by incapacity to connect to the X server, but if $DISPLAY was not set then the fprintf would be given a NULL pointer which it may not appreciate (depending on the libc in use). Let's avoid that case and try to provide more info to help the user. Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
		
							parent
							
								
									4be6166084
								
							
						
					
					
						commit
						2d191d0e6c
					
				
					 1 changed files with 14 additions and 2 deletions
				
			
		
							
								
								
									
										16
									
								
								wmix/wmix.c
									
									
									
									
									
								
							
							
						
						
									
										16
									
								
								wmix/wmix.c
									
									
									
									
									
								
							|  | @ -161,8 +161,20 @@ int main(int argc, char **argv) | |||
|     mixer_init(mixer_device, verbose, (const char **)exclude); | ||||
|     mixer_set_channel(0); | ||||
| 
 | ||||
|     if ((display = XOpenDisplay(display_name)) == NULL) { | ||||
| 	fprintf(stderr, "Unable to open display \"%s\"\n", display_name); | ||||
|     display = XOpenDisplay(display_name); | ||||
|     if (display == NULL) { | ||||
| 	const char *name; | ||||
| 
 | ||||
| 	if (display_name) { | ||||
| 	    name = display_name; | ||||
| 	} else { | ||||
| 	    name = getenv("DISPLAY"); | ||||
| 	    if (name == NULL) { | ||||
| 		fprintf(stderr, "wmix:error: Unable to open display, variable $DISPLAY not set\n"); | ||||
| 		return EXIT_FAILURE; | ||||
| 	    } | ||||
| 	} | ||||
| 	fprintf(stderr, "wmix:error: Unable to open display \"%s\"\n", name); | ||||
| 	return EXIT_FAILURE; | ||||
|     } | ||||
|     display_width = (float)DisplayWidth(display, DefaultScreen(display)) / 4.0; | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue