c.lang.correctness.goto-fail.double_goto

profile photo of returntocorpreturntocorp
Author
247
Download Count*

The second goto statement will always be executed.

Run Locally

Run in CI

Defintion

rules:
  - id: double_goto
    pattern: |
      if ($COND)
        goto $FAIL;
        goto $FAIL;
    message: The second goto statement will always be executed.
    languages:
      - c
    severity: WARNING
    metadata:
      category: correctness
      technology:
        - c
      license: Commons Clause License Condition v1.0[LGPL-2.1-only]

Examples

goto-fail.c

#include <stdio.h>

int
ok() {
    // ok:double_goto
    if (0) {
        goto ONE;
        goto ONE;
    }
    printf("did not go to one\n");
    return 0;
ONE:
    printf("went to one\n");
    return 1;
}

int
main(int argc, char *argv[]) {
    // ruleid:double_goto
    if (0)
        goto ONE;
        goto ONE;
    printf("did not go to one\n");
    return 0;
ONE:
    printf("went to one\n");
    return 1;
}