From f32fc33a01d6b199ccecb7cb38eeb773c20585f5 Mon Sep 17 00:00:00 2001 From: Avra Sengupta Date: Mon, 14 Jul 2014 13:07:08 +0000 Subject: gluster: Fix the recursive goto outs in the source code. Added a script check_goto.pl, that when run from the source code root, will scan all .c files to match the following pattern: label: if (condition) goto label; On finding such a pattern the script will print the file name and the line number. There are certain cases where the above recursive pattern is intended. Hence adding those labels to ignore-labels. Thanks Vijaikumar Mallikarjuna for the perl script. Also fixed all such existing errors BUG: 1138952 Change-Id: Ie6b75621711736e7e30f2f9d25e50435d58fc1e2 Signed-off-by: Vijaikumar Mallikarjuna Signed-off-by: Avra Sengupta Reviewed-on: http://review.gluster.org/8307 Tested-by: Gluster Build System Reviewed-by: Jeff Darcy Reviewed-by: Krishnan Parthasarathi Tested-by: Krishnan Parthasarathi Reviewed-on: http://review.gluster.org/8637 Reviewed-by: Vijay Bellur --- extras/check_goto.pl | 45 +++++++++++++++++++++++++++++++++++++++++++++ extras/test/test-ffop.c | 4 +--- 2 files changed, 46 insertions(+), 3 deletions(-) create mode 100755 extras/check_goto.pl (limited to 'extras') diff --git a/extras/check_goto.pl b/extras/check_goto.pl new file mode 100755 index 00000000000..fa71bfc6683 --- /dev/null +++ b/extras/check_goto.pl @@ -0,0 +1,45 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +my @ignore_labels = qw (TODO retry fetch_data again try_again sp_state_read_proghdr redo disabled_loop fd_alloc_try_again); +my @ignore_files = qw (y.tab.c lex.c); +my @c_files; +my $line; +my @labels; +my $in_comments; + +{ + local $" = "|"; + my $cmd = "find . -type f -name '*.c' | grep -vE '(@ignore_files)'"; + @c_files = `$cmd`; +} + +foreach my $file (@c_files) { + chomp ($file); + open FD, $file or die ("Failed to read file $file: $!"); + @labels = (); + $in_comments = 0; + while ($line = ) { + chomp ($line); + + next if $line =~ /^\s*(#|\/\/)/; + $in_comments = 1 if ($line =~ /\/\*/); + $in_comments = 0 if ($line =~ /\*\//); + + next if $in_comments; + if ($line =~ /^\s*(([a-zA-Z]|_)\w*)\s*:/) { + push (@labels, $1) unless grep (/$1/, @ignore_labels); + } + @labels = () if $line =~ /^}/; + + next unless @labels; + if ($line =~ /^\s*goto\s*(\w+)/) { + print "$file:$.: $line\n" if grep /^$1$/, @labels; + } + } + + close FD; +} + diff --git a/extras/test/test-ffop.c b/extras/test/test-ffop.c index 2d174d45276..219dd6a2da2 100644 --- a/extras/test/test-ffop.c +++ b/extras/test/test-ffop.c @@ -518,10 +518,8 @@ out: if (newfd) close (newfd); ret = unlink (filename); - if (ret < 0) { + if (ret < 0) fprintf (stderr, "unlink failed : %s\n", strerror (errno)); - goto out; - } return ret; } -- cgit