[PATCH] s3: Remove check of constant condition in loop
Swen Schillig
swen at vnet.ibm.com
Tue Mar 6 10:46:18 UTC 2018
Please review ...and push.
Thanks in advance.
Cheers Swen
-------------- next part --------------
From 07db00b51bc29e57adfa0a42952a1e61060491e9 Mon Sep 17 00:00:00 2001
From: Swen Schillig <swen at vnet.ibm.com>
Date: Tue, 6 Mar 2018 08:43:46 +0100
Subject: [PATCH] s3: Remove check of constant condition in loop
The function SearchDir contains three loops which check,
for each iteration, whether a string comparison is to be performed
case sesitive or not.
But this condition does not change between loop iterations.
Therefore, introduce a function pointer which is set at the beginning
according to the case sesitivity setting and executes the correct
string comparison in the succeeding code paths.
Signed-off-by: Swen Schillig <swen at vnet.ibm.com>
---
source3/smbd/dir.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c
index 1cd85e7f37d..eba1fbb5db5 100644
--- a/source3/smbd/dir.c
+++ b/source3/smbd/dir.c
@@ -1960,12 +1960,17 @@ bool SearchDir(struct smb_Dir *dirp, const char *name, long *poffset)
const char *entry = NULL;
char *talloced = NULL;
connection_struct *conn = dirp->conn;
+ bool (*str_eq)(const char *, const char *) = NULL;
+ bool strequal_cs(const char *s1, const char *s2)
+ { return (strcmp(s1, s2) == 0); }
+
+ str_eq = (conn->case_sensitive) ? strequal_cs : strequal;
/* Search back in the name cache. */
if (dirp->name_cache_size && dirp->name_cache) {
for (i = dirp->name_cache_index; i >= 0; i--) {
struct name_cache_entry *e = &dirp->name_cache[i];
- if (e->name && (conn->case_sensitive ? (strcmp(e->name, name) == 0) : strequal(e->name, name))) {
+ if (e->name && str_eq(e->name, name)) {
*poffset = e->offset;
SeekDir(dirp, e->offset);
return True;
@@ -1973,7 +1978,7 @@ bool SearchDir(struct smb_Dir *dirp, const char *name, long *poffset)
}
for (i = dirp->name_cache_size - 1; i > dirp->name_cache_index; i--) {
struct name_cache_entry *e = &dirp->name_cache[i];
- if (e->name && (conn->case_sensitive ? (strcmp(e->name, name) == 0) : strequal(e->name, name))) {
+ if (e->name && str_eq(e->name, name)) {
*poffset = e->offset;
SeekDir(dirp, e->offset);
return True;
@@ -1986,7 +1991,7 @@ bool SearchDir(struct smb_Dir *dirp, const char *name, long *poffset)
dirp->file_number = 0;
*poffset = START_OF_DIRECTORY_OFFSET;
while ((entry = ReadDirName(dirp, poffset, NULL, &talloced))) {
- if (conn->case_sensitive ? (strcmp(entry, name) == 0) : strequal(entry, name)) {
+ if (str_eq(entry, name)) {
TALLOC_FREE(talloced);
return True;
}
--
2.14.3
More information about the samba-technical
mailing list