Skip to content

If statements that are never executed #653

@tsh-hashimoto

Description

@tsh-hashimoto

Hello.

In configuration file (e.g. default.conf), some parameters are set to archaic or obsolete.
If this parameter is set to archaic or obsolete, a warning should appear when using the corresponding syntax, but it does not.

According to cb_verify function in cobj/error.c, it is implemented as follows:

int cb_verify(const enum cb_support tag, const char *feature) {
  switch (tag) {
  case CB_OK:
    return 1;
  case CB_WARNING:
    return 1;
  case CB_ARCHAIC:
    if (cb_warn_archaic) {
      cb_warning(_("%s is archaic in %s"), feature, cb_config_name);
    }
    return 1;
  case CB_OBSOLETE:
    if (cb_warn_obsolete) {
      cb_warning(_("%s is obsolete in %s"), feature, cb_config_name);
    }
    return 1;
  case CB_SKIP:
    return 0;
  case CB_IGNORE:
    cb_warning(_("%s ignored"), feature);
    return 0;
  case CB_ERROR:
    return 0;
  case CB_UNCONFORMABLE:
    cb_error(_("%s does not conform to %s"), feature, cb_config_name);
    return 0;
  }
  return 0;
}

It appears that the if condition required for the warning (i.e. cb_warn_obsolete is 1) to appear is not true.

I had tried to debug with the following code:

case CB_OBSOLETE:
    printf("cb_warn_obsolete: %d\n", cb_warn_obsolete);
    if (cb_warn_obsolete) {
      cb_warning(_("%s is obsolete in %s"), feature, cb_config_name);
    }
    return 1;

Upon execution, the case seems to be correctly determined, but this variable is 0.

cb_warn_obsolete: 0

This variable seems to be used only in warning.def.
But, it doesn't to be turned to 1 when set to obsolete.

/* CB_WARNDEF (var, name, wall, doc) */

CB_WARNDEF (cb_warn_obsolete, "obsolete", 1,
	    N_("Warn if obsolete features are used"))

If I eliminate if statement, I will get warning... I don't know if this is the right way, but I was able to get the behavior I was looking for.

case CB_OBSOLETE:
    // if (cb_warn_obsolete) {
      cb_warning(_("%s is obsolete in %s"), feature, cb_config_name);
    // }
    return 1;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions