From 98759f7bed3768ef150dcd41f97f87cbb84be8b1 Mon Sep 17 00:00:00 2001 From: rbuj Date: Mon, 21 Dec 2020 16:38:28 +0100 Subject: Remove cppcheck warnings about the variable scope can be reduced --- src/file-data.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'src/file-data.c') diff --git a/src/file-data.c b/src/file-data.c index 53a6f85..911a5e9 100644 --- a/src/file-data.c +++ b/src/file-data.c @@ -147,9 +147,9 @@ int find_path_in_file_data_array (GPtrArray *array, const char *path) { - int path_l; - int left, right, p, cmp = -1; - FileData *fd; + int path_l; + int left; + int right; if (path == NULL) return -1; @@ -158,16 +158,23 @@ find_path_in_file_data_array (GPtrArray *array, left = 0; right = array->len; while (left < right) { + FileData *fd; + int p; + int cmp; + p = left + ((right - left) / 2); fd = (FileData *) g_ptr_array_index (array, p); - cmp = strcmp (path, fd->original_path); if (cmp != 0) { /* consider '/path/to/dir' and '/path/to/dir/' the same path */ + int original_path_l; + + original_path_l = strlen (fd->original_path); - int original_path_l = strlen (fd->original_path); if ((path_l == original_path_l - 1) && (fd->original_path[original_path_l - 1] == '/')) { - int cmp2 = strncmp (path, fd->original_path, original_path_l - 1); + int cmp2; + + cmp2 = strncmp (path, fd->original_path, original_path_l - 1); if (cmp2 == 0) cmp = cmp2; } -- cgit v1.2.1