audio: replaced copyAudioFormat() with simple assignment
The "!src" check in copyAudioFormat() used to hide bugs - one should never pass NULL to it. There is one caller which might pass NULL, add a check in this caller. Instead of doing mempcy(), we can simply assign the structures, which looks more natural.
This commit is contained in:
		
							
								
								
									
										18
									
								
								src/audio.c
									
									
									
									
									
								
							
							
						
						
									
										18
									
								
								src/audio.c
									
									
									
									
									
								
							| @@ -66,14 +66,6 @@ static unsigned int audio_output_count(void) | |||||||
| 	return nr; | 	return nr; | ||||||
| } | } | ||||||
|  |  | ||||||
| void copyAudioFormat(struct audio_format *dest, const struct audio_format *src) |  | ||||||
| { |  | ||||||
| 	if (!src) |  | ||||||
| 		return; |  | ||||||
|  |  | ||||||
| 	memcpy(dest, src, sizeof(*dest)); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| int cmpAudioFormat(const struct audio_format *f1, const struct audio_format *f2) | int cmpAudioFormat(const struct audio_format *f1, const struct audio_format *f2) | ||||||
| { | { | ||||||
| 	if (f1 && f2 && (f1->sampleRate == f2->sampleRate) && | 	if (f1 && f2 && (f1->sampleRate == f2->sampleRate) && | ||||||
| @@ -130,10 +122,9 @@ void initAudioDriver(void) | |||||||
| void getOutputAudioFormat(const struct audio_format *inAudioFormat, | void getOutputAudioFormat(const struct audio_format *inAudioFormat, | ||||||
| 			  struct audio_format *outAudioFormat) | 			  struct audio_format *outAudioFormat) | ||||||
| { | { | ||||||
| 	if (audio_configFormat) { | 	*outAudioFormat = audio_configFormat != NULL | ||||||
| 		copyAudioFormat(outAudioFormat, audio_configFormat); | 		? *audio_configFormat | ||||||
| 	} else | 		: *inAudioFormat; | ||||||
| 		copyAudioFormat(outAudioFormat, inAudioFormat); |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void initAudioConfig(void) | void initAudioConfig(void) | ||||||
| @@ -316,7 +307,8 @@ int openAudioDevice(const struct audio_format *audioFormat) | |||||||
|  |  | ||||||
| 	if (!audioOpened || !isCurrentAudioFormat(audioFormat)) { | 	if (!audioOpened || !isCurrentAudioFormat(audioFormat)) { | ||||||
| 		flushAudioBuffer(); | 		flushAudioBuffer(); | ||||||
| 		copyAudioFormat(&audio_format, audioFormat); | 		if (audioFormat != NULL) | ||||||
|  | 			audio_format = *audioFormat; | ||||||
| 		audioBufferSize = (audio_format.bits >> 3) * | 		audioBufferSize = (audio_format.bits >> 3) * | ||||||
| 		    audio_format.channels; | 		    audio_format.channels; | ||||||
| 		audioBufferSize *= audio_format.sampleRate >> 5; | 		audioBufferSize *= audio_format.sampleRate >> 5; | ||||||
|   | |||||||
| @@ -27,8 +27,6 @@ struct audio_format; | |||||||
| struct tag; | struct tag; | ||||||
| struct client; | struct client; | ||||||
|  |  | ||||||
| void copyAudioFormat(struct audio_format *dest, const struct audio_format *src); |  | ||||||
|  |  | ||||||
| int cmpAudioFormat(const struct audio_format *dest, const struct audio_format *src); | int cmpAudioFormat(const struct audio_format *dest, const struct audio_format *src); | ||||||
|  |  | ||||||
| void getOutputAudioFormat(const struct audio_format *inFormat, | void getOutputAudioFormat(const struct audio_format *inFormat, | ||||||
|   | |||||||
| @@ -32,14 +32,12 @@ int audio_output_open(struct audio_output *audioOutput, | |||||||
| 		return 0; | 		return 0; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	copyAudioFormat(&audioOutput->inAudioFormat, audioFormat); | 	audioOutput->inAudioFormat = *audioFormat; | ||||||
|  |  | ||||||
| 	if (audioOutput->convertAudioFormat) { | 	if (audioOutput->convertAudioFormat) { | ||||||
| 		copyAudioFormat(&audioOutput->outAudioFormat, | 		audioOutput->outAudioFormat = audioOutput->reqAudioFormat; | ||||||
| 		                &audioOutput->reqAudioFormat); |  | ||||||
| 	} else { | 	} else { | ||||||
| 		copyAudioFormat(&audioOutput->outAudioFormat, | 		audioOutput->outAudioFormat = audioOutput->inAudioFormat; | ||||||
| 		                &audioOutput->inAudioFormat); |  | ||||||
| 		if (audioOutput->open) | 		if (audioOutput->open) | ||||||
| 			audio_output_close(audioOutput); | 			audio_output_close(audioOutput); | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -103,7 +103,7 @@ int audio_output_init(struct audio_output *ao, ConfigParam * param) | |||||||
| 			FATAL("error parsing format at line %i\n", bp->line); | 			FATAL("error parsing format at line %i\n", bp->line); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		copyAudioFormat(&ao->outAudioFormat, &ao->reqAudioFormat); | 		ao->outAudioFormat = ao->reqAudioFormat; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if (plugin->init(ao, param) != 0) | 	if (plugin->init(ao, param) != 0) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Max Kellermann
					Max Kellermann