Commit 048eb2dd authored by Maria Matejka's avatar Maria Matejka
Browse files

Merge remote-tracking branch 'origin/mq-static-analysis'

parents 17de3a02 59238768
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -184,6 +184,15 @@ check: tests tests_run
tests: $(tests_targets)
tests_run: $(tests_targets_ok)

STATIC_CHECKERS_ENABLE := nullability.NullableDereferenced nullability.NullablePassedToNonnull nullability.NullableReturnedFromNonnull optin.portability.UnixAPI valist.CopyToSelf valist.Uninitialized valist.Unterminated
STATIC_CHECKERS_DISABLE := deadcode.DeadStores
STATIC_SCAN_FLAGS := -o $(objdir)/static-scan/ $(addprefix -enable-checker ,$(STATIC_CHECKERS_ENABLE)) $(addprefix -disable-checker ,$(STATIC_CHECKERS_DISABLE))

static-scan:
	$(E)echo Running static code analysis
	$(Q)$(MAKE) clean
	$(Q)scan-build $(STATIC_SCAN_FLAGS) $(MAKE) -$(MAKEFLAGS)

tags:
	cd $(srcdir) ; etags -lc `find $(dirs) -name *.[chY]`

+7 −7
Original line number Diff line number Diff line
@@ -169,7 +169,7 @@ WHITE [ \t]

  errno = 0;
  l = bstrtoul10(yytext, &e);
  if (e && (*e != ':') || (errno == ERANGE) || (l >> 32))
  if (!e || (*e != ':') || (errno == ERANGE) || (l >> 32))
    cf_error("ASN out of range");

  if (l >> 16)
@@ -187,7 +187,7 @@ WHITE [ \t]

  errno = 0;
  l = bstrtoul10(e+1, &e);
  if (e && *e || (errno == ERANGE) || (l >> len2))
  if (!e || *e || (errno == ERANGE) || (l >> len2))
    cf_error("Number out of range");
  cf_lval.i64 |= l;

@@ -214,13 +214,13 @@ WHITE [ \t]

  errno = 0;
  l = bstrtoul10(yytext+2, &e);
  if (e && (*e != ':') || (errno == ERANGE) || (l >> len1))
  if (!e || (*e != ':') || (errno == ERANGE) || (l >> len1))
    cf_error("ASN out of range");
  cf_lval.i64 |= ((u64) l) << len2;

  errno = 0;
  l = bstrtoul10(e+1, &e);
  if (e && *e || (errno == ERANGE) || (l >> len2))
  if (!e || *e || (errno == ERANGE) || (l >> len2))
    cf_error("Number out of range");
  cf_lval.i64 |= l;

@@ -242,7 +242,7 @@ WHITE [ \t]

  errno = 0;
  l = bstrtoul10(e, &e);
  if (e && *e || (errno == ERANGE) || (l >> 16))
  if (!e || *e || (errno == ERANGE) || (l >> 16))
    cf_error("Number out of range");
  cf_lval.i64 |= l;

@@ -266,7 +266,7 @@ WHITE [ \t]
  unsigned long int l;
  errno = 0;
  l = bstrtoul16(yytext+2, &e);
  if (e && *e || errno == ERANGE || (unsigned long int)(unsigned int) l != l)
  if (!e || *e || errno == ERANGE || (unsigned long int)(unsigned int) l != l)
    cf_error("Number out of range");
  cf_lval.i = l;
  return NUM;
@@ -277,7 +277,7 @@ WHITE [ \t]
  unsigned long int l;
  errno = 0;
  l = bstrtoul10(yytext, &e);
  if (e && *e || errno == ERANGE || (unsigned long int)(unsigned int) l != l)
  if (!e || *e || errno == ERANGE || (unsigned long int)(unsigned int) l != l)
    cf_error("Number out of range");
  cf_lval.i = l;
  return NUM;
+13 −0
Original line number Diff line number Diff line
@@ -24,6 +24,12 @@ AC_ARG_ENABLE([debug-generated],
  [enable_debug_generated=no]
)

AC_ARG_ENABLE([debug-expensive],
  [AS_HELP_STRING([--enable-debug-expensive], [enable expensive consistency checks (implies --enable-debug) @<:@no@:>@])],
  [],
  [enable_debug_expensive=no]
)

AC_ARG_ENABLE([memcheck],
  [AS_HELP_STRING([--enable-memcheck], [check memory allocations when debugging @<:@yes@:>@])],
  [],
@@ -72,6 +78,9 @@ AC_ARG_VAR([FLEX], [location of the Flex program])
AC_ARG_VAR([BISON], [location of the Bison program])
AC_ARG_VAR([M4], [location of the M4 program])

if test "$enable_debug_expensive" = yes; then
  enable_debug=yes
fi

if test "$srcdir" = . ; then
  # Building in current directory => create obj directory holding all objects
@@ -388,6 +397,10 @@ if test "$enable_debug" = yes ; then
      AC_CHECK_LIB([efence], [malloc])
    fi
  fi

  if test "enable_debug_expensive" = yes ; then
    AC_DEFINE([ENABLE_EXPENSIVE_CHECKS], [1], [Define to 1 if you want to run expensive consistency checks.])
  fi
fi

CLIENT=birdcl
+0 −153
Original line number Diff line number Diff line
@@ -185,159 +185,6 @@ f_generate_empty(struct f_dynamic_attr dyn)
  return f_new_inst(FI_EA_SET, f_new_inst(FI_CONSTANT, empty), dyn);
}

#if 0

static inline struct f_inst *
f_generate_dpair(struct f_inst *t1, struct f_inst *t2)
{
  struct f_inst *rv;

  if ((t1->fi_code == FI_CONSTANT) && (t2->fi_code == FI_CONSTANT)) {
    if ((t1->val.type != T_INT) || (t2->val.type != T_INT))
      cf_error( "Can't operate with value of non-integer type in pair constructor");

    check_u16(t1->a[1].i);
    check_u16(t2->a[1].i);

    rv = f_new_inst(FI_CONSTANT);
    rv->val = (struct f_val) {
      .type = T_PAIR,
      .val.i = pair(t1->a[1].i, t2->a[1].i),
    };
  }
  else {
    rv = f_new_inst(FI_PAIR_CONSTRUCT);
    rv->a[0].p = t1;
    rv->a[1].p = t2;
  }

  return rv;
}

static inline struct f_inst *
f_generate_ec(u16 kind, struct f_inst *tk, struct f_inst *tv)
{
  struct f_inst *rv;
  int c1 = 0, c2 = 0, ipv4_used = 0;
  u32 key = 0, val2 = 0;

  if (tk->fi_code == FI_CONSTANT) {
    c1 = 1;
    struct f_val *val = &(tk->val);

    if (val->type == T_INT) {
      ipv4_used = 0; key = val->val.i;
    }
    else if (tk->val.type == T_QUAD) {
      ipv4_used = 1; key = val->val.i;
    }
    else if ((val->type == T_IP) && ipa_is_ip4(val->val.ip)) {
      ipv4_used = 1; key = ipa_to_u32(val->val.ip);
    }
    else
      cf_error("Can't operate with key of non-integer/IPv4 type in EC constructor");
  }

  if (tv->fi_code == FI_CONSTANT) {
    if (tv->val.type != T_INT)
      cf_error("Can't operate with value of non-integer type in EC constructor");
    c2 = 1;
    val2 = tv->val.val.i;
  }

  if (c1 && c2) {
    u64 ec;

    if (kind == EC_GENERIC) {
      ec = ec_generic(key, val2);
    }
    else if (ipv4_used) {
      check_u16(val2);
      ec = ec_ip4(kind, key, val2);
    }
    else if (key < 0x10000) {
      ec = ec_as2(kind, key, val2);
    }
    else {
      check_u16(val2);
      ec = ec_as4(kind, key, val2);
    }

    rv = f_new_inst(FI_CONSTANT);
    rv->val = (struct f_val) {
      .type = T_EC,
      .val.ec = ec,
    };
  }
  else {
    rv = f_new_inst(FI_EC_CONSTRUCT);
    rv->aux = kind;
    rv->a[0].p = tk;
    rv->a[1].p = tv;
  }

  return rv;
}

static inline struct f_inst *
f_generate_lc(struct f_inst *t1, struct f_inst *t2, struct f_inst *t3)
{
  struct f_inst *rv;

  if ((t1->fi_code == FI_CONSTANT) && (t2->fi_code == FI_CONSTANT) && (t3->fi_code == FI_CONSTANT)) {
    if ((t1->val.type != T_INT) || (t2->val.type != T_INT) || (t3->val.type != T_INT))
      cf_error( "LC - Can't operate with value of non-integer type in tuple constructor");

    rv = f_new_inst(FI_CONSTANT);
    rv->val = (struct f_val) {
      .type = T_LC,
      .val.lc = (lcomm) { t1->a[1].i, t2->a[1].i, t3->a[1].i },
    };
  }
  else
  {
    rv = f_new_inst(FI_LC_CONSTRUCT);
    rv->a[0].p = t1;
    rv->a[1].p = t2;
    rv->a[2].p = t3;
  }

  return rv;
}

static inline struct f_inst *
f_generate_path_mask(struct f_inst *t)
{
  uint len = 0;
  uint dyn = 0;
  for (const struct f_inst *tt = t; tt; tt = tt->next) {
    if (tt->fi_code != FI_CONSTANT)
      dyn++;
    len++;
  }

  if (dyn) {
    struct f_inst *pmc = f_new_inst(FI_PATHMASK_CONSTRUCT);
    pmc->a[0].p = t;
    pmc->a[1].i = len;
    return pmc;
  }

  struct f_path_mask *pm = cfg_allocz(sizeof(struct f_path_mask) + len * sizeof(struct f_path_mask_item));

  uint i = 0;
  for (const struct f_inst *tt = t; tt; tt = tt->next)
    pm->item[i++] = tt->val.val.pmi;

  pm->len = i;
  struct f_inst *pmc = f_new_inst(FI_CONSTANT);
  pmc->val = (struct f_val) { .type = T_PATH_MASK, .val.path_mask = pm, };

  return pmc;
}

#endif

/*
 * Remove all new lines and doubled whitespaces
 * and convert all tabulators to spaces
+1 −1
Original line number Diff line number Diff line
@@ -138,7 +138,7 @@ FID_IFCONST([[
}
FID_IFCONST([[
  const struct f_inst **items = NULL;
  if (constargs) {
  if (constargs && whati->varcount) {
    items = alloca(whati->varcount * sizeof(struct f_inst *));
    const struct f_inst *child = fvar;
    for (uint i=0; child; i++)
Loading