bstr: check strings before memcmp/strncasecmp

bstr.start can be NULL when bstr.len is 0, so don't call memcmp or
strncasecmp if that's the case. Passing NULL to string functions is
invalid C, even when the length is 0, and it causes Windows to raise an
invalid parameter error.

Should fix #1155
This commit is contained in:
James Ross-Gowan 2014-10-07 15:42:30 +11:00 committed by wm4
parent ec7bc388d1
commit 476fc65b0f
1 changed files with 6 additions and 2 deletions

View File

@ -33,7 +33,9 @@
int bstrcmp(struct bstr str1, struct bstr str2)
{
int ret = memcmp(str1.start, str2.start, FFMIN(str1.len, str2.len));
int ret = 0;
if (str1.len && str2.len)
ret = memcmp(str1.start, str2.start, FFMIN(str1.len, str2.len));
if (!ret) {
if (str1.len == str2.len)
@ -48,7 +50,9 @@ int bstrcmp(struct bstr str1, struct bstr str2)
int bstrcasecmp(struct bstr str1, struct bstr str2)
{
int ret = strncasecmp(str1.start, str2.start, FFMIN(str1.len, str2.len));
int ret = 0;
if (str1.len && str2.len)
ret = strncasecmp(str1.start, str2.start, FFMIN(str1.len, str2.len));
if (!ret) {
if (str1.len == str2.len)