Unverified Commit df6c5382 authored by teor's avatar teor
Browse files

Merge branch 'pr-1569-squashed'

parents a4c22164 92a6803e
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -168,6 +168,13 @@ EXTRA_DIST+= \
	ReleaseNotes							\
	scripts/maint/checkIncludes.py					\
	scripts/maint/checkSpace.pl					\
	scripts/maint/checkSpaceTest.sh					\
	scripts/maint/checkspace_tests/dubious.c			\
	scripts/maint/checkspace_tests/dubious.h			\
	scripts/maint/checkspace_tests/expected.txt			\
	scripts/maint/checkspace_tests/good_guard.h			\
	scripts/maint/checkspace_tests/same_guard.h			\
	scripts/maint/checkspace_tests/subdir/dubious.c			\
	scripts/maint/checkShellScripts.sh				\
	scripts/maint/practracker/README				\
	scripts/maint/practracker/exceptions.txt			\
+29 −22
Original line number Diff line number Diff line
@@ -4,9 +4,16 @@ use strict;
use warnings;

my $found = 0;
my $COLON_POS = 10;

sub msg {
  $found = 1;
  print "$_[0]";
  my $v = shift;
  $v =~ /^\s*([^:]+):(.*)$/;
  chomp(my $errtype = $1);
  my $rest = $2;
  my $padding = ' ' x ($COLON_POS - length $errtype);
  print "$padding$errtype:$rest\n";
}

my $C = 0;
@@ -29,7 +36,7 @@ for my $fn (@ARGV) {
    my $basename = $fn;
    $basename =~ s#.*/##;
    if ($basenames{$basename}) {
        msg "Duplicate fnames: $fn and $basenames{$basename}.\n";
        msg "dup fname:$fn (same as $basenames{$basename}).\n";
    } else {
        $basenames{$basename} = $fn;
    }
@@ -156,7 +163,7 @@ for my $fn (@ARGV) {
            }
            ## Warn about double semi-colons at the end of a line.
            if (/;;$/) {
                msg "       double semi-colons at the end of $. in $fn\n"
                msg ";;:$fn:$.\n"
            }
            ## Warn about multiple internal spaces.
            #if (/[^\s,:]\s{2,}[^\s\\=]/) {
@@ -225,9 +232,9 @@ for my $fn (@ARGV) {
    }
    if ($isheader && $C) {
        if ($seenguard < 2) {
            msg "$fn:No #ifndef/#define header guard pair found.\n";
            msg "noguard:$fn (No #ifndef/#define header guard pair found)\n";
        } elsif ($guardnames{$guardname}) {
            msg "$fn:Guard macro $guardname also used in $guardnames{$guardname}\n";
            msg "dupguard:$fn (Guard macro $guardname also used in $guardnames{$guardname})\n";
        } else {
            $guardnames{$guardname} = $fn;
        }
+36 −0
Original line number Diff line number Diff line
#!/bin/sh
# Copyright 2019, The Tor Project, Inc.
# See LICENSE for licensing information

# Integration test for checkSpace.pl, which we want to rewrite.

umask 077
set -e

# Skip this test if we're running on Windows; we expect line-ending
# issues in that case.
case "$(uname -s)" in
    CYGWIN*) WINDOWS=1;;
    MINGW*) WINDOWS=1;;
    MSYS*) WINDOWS=1;;
    *) WINDOWS=0;;
esac
if test "$WINDOWS" = 1; then
    # This magic value tells automake that the test has been skipped.
    exit 77
fi

# make a safe space for temporary files
DATA_DIR=$(mktemp -d -t tor_checkspace_tests.XXXXXX)
trap 'rm -rf "$DATA_DIR"' 0

RECEIVED_FNAME="${DATA_DIR}/got.txt"

cd "$(dirname "$0")/checkspace_tests"

# we expect this to give an error code.
../checkSpace.pl -C ./*.[ch] ./*/*.[ch] > "${RECEIVED_FNAME}" && exit 1

diff -u expected.txt "${RECEIVED_FNAME}" || exit 1

echo "OK"
+83 −0
Original line number Diff line number Diff line

// The { coming up should be on its own line.
int
foo(void) {
  // There should be a space before (1)
  if(1) x += 1;

  // The following empty line is unnecessary.

}


// There should be a newline between void and bar.
void bar(void)
{
  // too wide:
  testing("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
}

long
bad_spacing()
{
  // here comes a tab
	return 2;
  // here comes a label without space:
foo:
  ;
}

// Here comes a CR:

// Trailing space:         

int
non_k_and_r(void)
{
  // non-k&r
  if (foo)
    {
      // double-semi
      return 1;;
    }
  else
    {
      return 2;
    }
}

// #else #if causes a warning.
#if 1
#else
#if 2
#else
#endif
#endif

// always space before a brace.
foo{
}

void
unexpected_space(void)
{
  // This space gives a warning.
  foobar (77);
}

void
bad_function_calls(long)
{
  // These are forbidden:
  assert(1);
  memcmp("a","b",1);
  strcat(foo,x);
  strcpy(foo,y);
  sprintf(foo,"x");
  malloc(7);
  free(p);
  realloc(p);
  strdup(s);
  strndup(s,10);
  calloc(a,b);
}
+4 −0
Original line number Diff line number Diff line

// no guards.

int foo(int);
Loading