瀏覽代碼

libobs/util: Prevent null pointer deref with dstr_cmp

This makes it prevent any null pointer dereferences, and makes it
consistent with the other dstr compare functions.
Lain 1 年之前
父節點
當前提交
089ba29961
共有 1 個文件被更改,包括 3 次插入1 次删除
  1. 3 1
      libobs/util/dstr.h

+ 3 - 1
libobs/util/dstr.h

@@ -287,7 +287,9 @@ static inline const char *dstr_find(const struct dstr *str, const char *find)
 
 static inline int dstr_cmp(const struct dstr *str1, const char *str2)
 {
-	return strcmp(str1->array, str2);
+	const char *s1 = str1->array ? str1->array : "";
+	const char *s2 = str2 ? str2 : "";
+	return strcmp(s1, s2);
 }
 
 static inline int dstr_cmpi(const struct dstr *str1, const char *str2)