findutils-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Findutils-patches] [PATCH 3/5] maint: avoid -Werror=unsafe-loop-optimiz


From: Bernhard Voelker
Subject: [Findutils-patches] [PATCH 3/5] maint: avoid -Werror=unsafe-loop-optimizations warning in oldfind
Date: Thu, 2 Feb 2017 00:17:21 +0100

oldfind.c: In function ‘process_path’:
oldfind.c:1445:14: error: cannot optimize loop, the loop counter may overflow 
[-Werror=unsafe-loop-optimizations]
        while (cur_path_size < file_len)
              ^
cc1: all warnings being treated as errors

* find/oldfind.c (process_path): Replace loop by calculation, avoiding
the offending loop at all.
---
 find/oldfind.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/find/oldfind.c b/find/oldfind.c
index 49e17966..4a68de94 100644
--- a/find/oldfind.c
+++ b/find/oldfind.c
@@ -1454,8 +1454,7 @@ process_dir (const char *pathname, const char *name, int 
pathlen, const struct s
          file_len = pathname_len + strlen (namep);
          if (file_len > cur_path_size)
            {
-             while (file_len > cur_path_size)
-               cur_path_size += 1024;
+             cur_path_size = (file_len/1024 + 1) * 1024;
              free (cur_path);
              cur_path = xmalloc (cur_path_size);
              strcpy (cur_path, pathname);
-- 
2.11.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]