files: Fix compilation errors

Submitted by Pavel Begunkov (Silence) on June 19, 2017, 11:18 a.m.

Details

Message ID 20170619111834.24513-1-asml.silence@gmail.com
State Accepted
Series "files: Fix compilation errors"
Headers show

Commit Message

Pavel Begunkov (Silence) June 19, 2017, 11:18 a.m.
1: Signed underflow
criu/files-reg.c: In function ‘open_path’:
criu/files-reg.c:1299:14: error: iteration 2147483647
invokes undefined behavior [-Werror=aggressive-loop-optimizations]
  while (count--) {
         ~~~~~^~

2: Uninitialized variable
criu/files-reg.c: In function ‘make_parent_dirs_if_need’:
criu/files-reg.c:1354:13: warning: ‘count’ may be used uninitialized in
  this function [-Wmaybe-uninitialized]

P.S. arch linux 4.7.5-1. gcc (GCC) 6.3.1 20170109

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
---
 criu/files-reg.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/files-reg.c b/criu/files-reg.c
index 7c81d182..dfc3f29a 100644
--- a/criu/files-reg.c
+++ b/criu/files-reg.c
@@ -1296,7 +1296,8 @@  static void rm_parent_dirs(int mntns_root, char *path, int count)
 	if (!count)
 		return;
 
-	while (count--) {
+	while (count > 0) {
+		count -= 1;
 		p = strrchr(path, '/');
 		if (p)
 			*p = '\0';
@@ -1431,7 +1432,7 @@  out_root:
 int open_path(struct file_desc *d,
 		int(*open_cb)(int mntns_root, struct reg_file_info *, void *), void *arg)
 {
-	int tmp, mntns_root, level;
+	int tmp, mntns_root, level = 0;
 	struct reg_file_info *rfi;
 	char *orig_path = NULL;
 	char path[PATH_MAX];

Comments

Andrey Vagin June 27, 2017, 11:19 p.m.
Applied, thanks!

On Mon, Jun 19, 2017 at 02:18:34PM +0300, Pavel Begunkov wrote:
> 1: Signed underflow
> criu/files-reg.c: In function ‘open_path’:
> criu/files-reg.c:1299:14: error: iteration 2147483647
> invokes undefined behavior [-Werror=aggressive-loop-optimizations]
>   while (count--) {
>          ~~~~~^~
> 
> 2: Uninitialized variable
> criu/files-reg.c: In function ‘make_parent_dirs_if_need’:
> criu/files-reg.c:1354:13: warning: ‘count’ may be used uninitialized in
>   this function [-Wmaybe-uninitialized]
> 
> P.S. arch linux 4.7.5-1. gcc (GCC) 6.3.1 20170109
> 
> Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
> ---
>  criu/files-reg.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/criu/files-reg.c b/criu/files-reg.c
> index 7c81d182..dfc3f29a 100644
> --- a/criu/files-reg.c
> +++ b/criu/files-reg.c
> @@ -1296,7 +1296,8 @@ static void rm_parent_dirs(int mntns_root, char *path, int count)
>  	if (!count)
>  		return;
>  
> -	while (count--) {
> +	while (count > 0) {
> +		count -= 1;
>  		p = strrchr(path, '/');
>  		if (p)
>  			*p = '\0';
> @@ -1431,7 +1432,7 @@ out_root:
>  int open_path(struct file_desc *d,
>  		int(*open_cb)(int mntns_root, struct reg_file_info *, void *), void *arg)
>  {
> -	int tmp, mntns_root, level;
> +	int tmp, mntns_root, level = 0;
>  	struct reg_file_info *rfi;
>  	char *orig_path = NULL;
>  	char path[PATH_MAX];
> -- 
> 2.11.1
> 
> _______________________________________________
> CRIU mailing list
> CRIU@openvz.org
> https://lists.openvz.org/mailman/listinfo/criu