Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-53823

Expression always true

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.0.3
    • Fix Version/s: None
    • Component/s: Navigation
    • Labels:
    • Difficulty:
      Easy
    • Affected Branches:
      MOODLE_30_STABLE

      Description

      In file moodle/lib/navigationlib.php at line 1592 there is a expression

      (($category->type != self::TYPE_CATEGORY) || ($category->type != self::TYPE_MY_CATEGORY)) 
      

      But it is always true:
      if $category->type is self::TYPE_CATEGORY then ($category->type != self::TYPE_CATEGORY) is true, so whole expression is true
      if $category->type is self::TYPE_MY_CATEGORY then ($category->type != self::TYPE_MY_CATEGORY) is true, so whole expression is true
      if $category->type is SOME_ANOTHER_TYPE then ($category->type != self::TYPE_CATEGORY) is true, so whole expression is true

      Probably, you should use "&&" operator instead of "||"

      GitHub link: https://github.com/moodle/moodle/blob/b611ade3abc7f19341db866a2d9c31f53909ba8e/lib/navigationlib.php#L1591

      The possible defect was found by static analyzer AppChecker

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            AppChecker AppChecker
            Participants:
            Component watchers:
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated: