From ada86316e54320a891d982c653e1070155bc8dbb Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 14 Aug 2004 05:57:43 +0000 Subject: r1820: added a strcmp_safe() that handles NULL pointers. Needed for the search torture test, as some servers return really bad entries. (This used to be commit c900ebb3ac18d77ab334d3bf5259b3bba547b09c) --- source4/lib/util_str.c | 15 +++++++++++++++ source4/torture/raw/search.c | 10 +++++----- 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'source4') diff --git a/source4/lib/util_str.c b/source4/lib/util_str.c index fd13f86501..a6f54f9a8d 100644 --- a/source4/lib/util_str.c +++ b/source4/lib/util_str.c @@ -1464,3 +1464,18 @@ BOOL add_string_to_array(TALLOC_CTX *mem_ctx, return True; } + + +/* + varient of strcmp() that handles NULL ptrs +*/ +int strcmp_safe(const char *s1, const char *s2) +{ + if (s1 == s2) { + return 0; + } + if (s1 == NULL || s2 == NULL) { + return s1?-1:1; + } + return strcmp(s1, s2); +} diff --git a/source4/torture/raw/search.c b/source4/torture/raw/search.c index f91c8083a5..f1d51a8c69 100644 --- a/source4/torture/raw/search.c +++ b/source4/torture/raw/search.c @@ -512,27 +512,27 @@ static NTSTATUS multiple_search(struct smbcli_state *cli, static int search_both_compare(union smb_search_data *d1, union smb_search_data *d2) { - return strcmp(d1->both_directory_info.name.s, d2->both_directory_info.name.s); + return strcmp_safe(d1->both_directory_info.name.s, d2->both_directory_info.name.s); } static int search_standard_compare(union smb_search_data *d1, union smb_search_data *d2) { - return strcmp(d1->standard.name.s, d2->standard.name.s); + return strcmp_safe(d1->standard.name.s, d2->standard.name.s); } static int search_ea_size_compare(union smb_search_data *d1, union smb_search_data *d2) { - return strcmp(d1->ea_size.name.s, d2->ea_size.name.s); + return strcmp_safe(d1->ea_size.name.s, d2->ea_size.name.s); } static int search_directory_info_compare(union smb_search_data *d1, union smb_search_data *d2) { - return strcmp(d1->directory_info.name.s, d2->directory_info.name.s); + return strcmp_safe(d1->directory_info.name.s, d2->directory_info.name.s); } static int search_old_compare(union smb_search_data *d1, union smb_search_data *d2) { - return strcmp(d1->search.name, d2->search.name); + return strcmp_safe(d1->search.name, d2->search.name); } -- cgit