Ver Fonte

libobs: Minor fixes / code cleanups

Fixes some warnings generated by code analysis tools, removing redundant
checks etc.
Richard Stanway há 4 anos atrás
pai
commit
6c0d234385

+ 2 - 2
libobs/obs-data.c

@@ -791,7 +791,7 @@ static void set_item_data(struct obs_data *data, struct obs_data_item **item,
 {
 	obs_data_item_t *new_item = NULL;
 
-	if ((!item || (item && !*item)) && data) {
+	if ((!item || !*item) && data) {
 		new_item = obs_data_item_create(name, ptr, size, type,
 						default_data, autoselect_data);
 
@@ -860,7 +860,7 @@ static inline void set_item_def(struct obs_data *data, obs_data_item_t **item,
 		item = &actual_item;
 	}
 
-	if (item && *item && (*item)->type != type)
+	if (*item && (*item)->type != type)
 		return;
 
 	set_item_data(data, item, name, ptr, size, type, true, false);

+ 1 - 1
libobs/obs-output-delay.c

@@ -31,7 +31,7 @@ static inline bool delay_capturing(const struct obs_output *output)
 static inline void push_packet(struct obs_output *output,
 			       struct encoder_packet *packet, uint64_t t)
 {
-	struct delay_data dd = {0};
+	struct delay_data dd;
 
 	dd.msg = DELAY_MSG_PACKET;
 	dd.ts = t;

+ 1 - 2
libobs/obs-source.c

@@ -2865,8 +2865,7 @@ obs_source_output_video_internal(obs_source_t *source,
 		return;
 	}
 
-	struct obs_source_frame *output = !!frame ? cache_video(source, frame)
-						  : NULL;
+	struct obs_source_frame *output = cache_video(source, frame);
 
 	/* ------------------------------------------- */
 	pthread_mutex_lock(&source->async_mutex);

+ 1 - 2
libobs/util/circlebuf.h

@@ -135,8 +135,7 @@ static inline void circlebuf_place(struct circlebuf *cb, size_t position,
 		size_t back_size = data_end_pos - cb->capacity;
 		size_t loop_size = size - back_size;
 
-		if (back_size)
-			memcpy((uint8_t *)cb->data + position, data, loop_size);
+		memcpy((uint8_t *)cb->data + position, data, loop_size);
 		memcpy(cb->data, (uint8_t *)data + loop_size, back_size);
 	} else {
 		memcpy((uint8_t *)cb->data + position, data, size);

+ 16 - 6
libobs/util/darray.h

@@ -88,10 +88,12 @@ static inline void darray_reserve(const size_t element_size, struct darray *dst,
 		return;
 
 	ptr = bmalloc(element_size * capacity);
-	if (dst->num)
-		memcpy(ptr, dst->array, element_size * dst->num);
-	if (dst->array)
+	if (dst->array) {
+		if (dst->num)
+			memcpy(ptr, dst->array, element_size * dst->num);
+
 		bfree(dst->array);
+	}
 	dst->array = ptr;
 	dst->capacity = capacity;
 }
@@ -109,10 +111,12 @@ static inline void darray_ensure_capacity(const size_t element_size,
 	if (new_size > new_cap)
 		new_cap = new_size;
 	ptr = bmalloc(element_size * new_cap);
-	if (dst->capacity)
-		memcpy(ptr, dst->array, element_size * dst->capacity);
-	if (dst->array)
+	if (dst->array) {
+		if (dst->capacity)
+			memcpy(ptr, dst->array, element_size * dst->capacity);
+
 		bfree(dst->array);
+	}
 	dst->array = ptr;
 	dst->capacity = new_cap;
 }
@@ -405,6 +409,9 @@ static inline void darray_move_item(const size_t element_size,
 		return;
 
 	temp = malloc(element_size);
+	if (!temp)
+		bcrash("darray_move_item: out of memory");
+
 	p_from = darray_item(element_size, dst, from);
 	p_to = darray_item(element_size, dst, to);
 
@@ -433,6 +440,9 @@ static inline void darray_swap(const size_t element_size, struct darray *dst,
 		return;
 
 	temp = malloc(element_size);
+	if (!temp)
+		bcrash("darray_swap: out of memory");
+
 	a_ptr = darray_item(element_size, dst, a);
 	b_ptr = darray_item(element_size, dst, b);
 

+ 1 - 1
libobs/util/platform.c

@@ -392,7 +392,7 @@ size_t os_wcs_to_mbs(const wchar_t *str, size_t len, char *dst, size_t dst_size)
 	if (!str)
 		return 0;
 
-	out_len = dst ? (dst_size - 1) : wcstombs(NULL, str, len);
+	out_len = dst ? (dst_size - 1) : wcstombs(NULL, str, 0);
 
 	if (dst) {
 		if (!dst_size)