Skip to content

[cpd] Found match is not maximal #4835

@jdupak

Description

@jdupak

Affects PMD Version: 6.55.0

image

void print_fence(short current_row, short fence_size) {
  short i = 0;
  if (current_row == 0 ||
      current_row == fence_size) { // checks for first and last row
    if (fence_size % 2 == 0) {     // checks if the fence is even
      for (; i < fence_size;
           i += 2) { // i += 2 because two characters are being printed
        printf("-|");
      }
    } else {
      printf("|");
      i++; // i++ because one character was printed
      for (; i < fence_size;
           i += 2) { // i += 2 because two characters are being printed
        printf("-|");
      }
    }
  } else {
    if (fence_size % 2 == 0) { // checks if the fence is even
      for (; i < fence_size;
           i += 2) { // i += 2 because two characters are being printed
        printf(" |");
      }
    } else {
      printf("|");
      i++; // i++ because one character was printed
      for (; i < fence_size;
           i += 2) { // i += 2 because two characters are being printed
        printf(" |");
      }
    }
  }
  printf("\n");
}

The for loop and if are also identical.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-negativePMD doesn't flag a problematic piece of codein:cpdAffects the copy-paste detectorwas:invalid

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions