Преглед изворни кода

Add NULL checks and assertions to fix clang static analysis problems

Also remove an unused variable from obs-encoder.c (via clang static
analysis)
Palana пре 11 година
родитељ
комит
3990c18aac

+ 3 - 0
libobs/graphics/graphics.c

@@ -809,13 +809,16 @@ void gs_draw_cube_backdrop(texture_t cubetex, const struct quat *rot,
 void gs_resetviewport(void)
 {
 	uint32_t cx, cy;
+	assert(thread_graphics != NULL);
 	gs_getsize(&cx, &cy);
+
 	gs_setviewport(0, 0, (int)cx, (int)cy);
 }
 
 void gs_set2dmode(void)
 {
 	uint32_t cx, cy;
+	assert(thread_graphics != NULL);
 	gs_getsize(&cx, &cy);
 
 	gs_ortho(0.0f, (float)cx, 0.0f, (float)cy, -1.0, -1024.0f);

+ 2 - 0
libobs/media-io/audio-io.c

@@ -575,6 +575,8 @@ int audio_output_open(audio_t *audio, struct audio_output_info *info)
 		return AUDIO_OUTPUT_INVALIDPARAM;
 
 	out = bzalloc(sizeof(struct audio_output));
+	if (!out)
+		goto fail;
 
 	memcpy(&out->info, info, sizeof(struct audio_output_info));
 	pthread_mutex_init_value(&out->line_mutex);

+ 2 - 0
libobs/media-io/video-io.c

@@ -165,6 +165,8 @@ int video_output_open(video_t *video, struct video_output_info *info)
 		return VIDEO_OUTPUT_INVALIDPARAM;
 
 	out = bzalloc(sizeof(struct video_output));
+	if (!out)
+		goto fail;
 
 	memcpy(&out->info, info, sizeof(struct video_output_info));
 	out->frame_time = (uint64_t)(1000000000.0 * (double)info->fps_den /

+ 3 - 8
libobs/obs-encoder.c

@@ -366,7 +366,6 @@ void obs_encoder_start(obs_encoder_t encoder,
 		void *param)
 {
 	struct encoder_callback cb = {false, new_packet, param};
-	bool success = true;
 	bool first   = false;
 
 	if (!encoder || !new_packet || !encoder->data) return;
@@ -375,13 +374,9 @@ void obs_encoder_start(obs_encoder_t encoder,
 
 	first = (encoder->callbacks.num == 0);
 
-	if (success) {
-		size_t idx = get_callback_idx(encoder, new_packet, param);
-		if (idx == DARRAY_INVALID)
-			da_push_back(encoder->callbacks, &cb);
-		else
-			success = false;
-	}
+	size_t idx = get_callback_idx(encoder, new_packet, param);
+	if (idx == DARRAY_INVALID)
+		da_push_back(encoder->callbacks, &cb);
 
 	pthread_mutex_unlock(&encoder->callbacks_mutex);
 

+ 4 - 0
libobs/obs-scene.c

@@ -130,6 +130,8 @@ static inline void attach_sceneitem(struct obs_scene_item *item,
 			prev->next->prev = item;
 		prev->next = item;
 	} else {
+		assert(item->parent != NULL);
+
 		item->next = item->parent->first_item;
 		item->parent->first_item = item;
 	}
@@ -406,6 +408,8 @@ void obs_sceneitem_remove(obs_sceneitem_t item)
 
 	item->removed = true;
 
+	assert(scene != NULL);
+	assert(scene->source != NULL);
 	obs_source_remove_child(scene->source, item->source);
 
 	signal_item_remove(item);

+ 2 - 0
libobs/obs.c

@@ -387,6 +387,8 @@ static bool obs_init_data(void)
 	struct obs_core_data *data = &obs->data;
 	pthread_mutexattr_t attr;
 
+	assert(data != NULL);
+
 	pthread_mutex_init_value(&obs->data.displays_mutex);
 
 	if (pthread_mutexattr_init(&attr) != 0)

+ 3 - 0
libobs/util/config-file.c

@@ -234,6 +234,9 @@ int config_open(config_t *config, const char *file,
 		return CONFIG_ERROR;
 
 	*config = bzalloc(sizeof(struct config_data));
+	if (!*config)
+		return CONFIG_ERROR;
+
 	(*config)->file = bstrdup(file);
 
 	errorcode = config_parse(&(*config)->sections, file, always_open);

+ 3 - 0
libobs/util/threading-posix.c

@@ -171,6 +171,9 @@ int  os_sem_init(os_sem_t *sem, int value)
 		return -1;
 
 	*sem = bzalloc(sizeof(struct os_sem_data));
+	if (!*sem)
+		return -2;
+
 	(*sem)->sem  = new_sem;
 	(*sem)->task = task;
 	return 0;

+ 3 - 0
libobs/util/threading.h

@@ -40,6 +40,9 @@ extern "C" {
 /* this may seem strange, but you can't use it unless it's an initializer */
 static inline void pthread_mutex_init_value(pthread_mutex_t *mutex)
 {
+	if (!mutex)
+		return;
+
 	pthread_mutex_t init_val = PTHREAD_MUTEX_INITIALIZER;
 	*mutex = init_val;
 }