prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  [Bug]: Infinite loop in RTLO detector
  ### What happened?
  
  Slither hangs on this code indefinitely
  
  ### Can you share code with us to reproduce this bug?
  
  https://github.com/ethereum/solidity/blob/develop/test/libsolidity/syntaxTests/comments/multiline_unicode_direction_override_5.sol
  
  ### Version
  
  0.8.2
  
  ### Relevant log output
  
  _No response_
  
  </issue>
  <code>
  [start of slither/detectors/source/rtlo.py]
  1 import re
  2 from slither.detectors.abstract_detector import AbstractDetector, DetectorClassification
  3 
  4 
  5 class RightToLeftOverride(AbstractDetector):
  6     """
  7     Detect the usage of a Right-To-Left-Override (U+202E) character
  8     """
  9 
  10     ARGUMENT = "rtlo"
  11     HELP = "Right-To-Left-Override control character is used"
  12     IMPACT = DetectorClassification.HIGH
  13     CONFIDENCE = DetectorClassification.HIGH
  14 
  15     WIKI = "https://github.com/crytic/slither/wiki/Detector-Documentation#right-to-left-override-character"
  16     WIKI_TITLE = "Right-to-Left-Override character"
  17     WIKI_DESCRIPTION = "An attacker can manipulate the logic of the contract by using a right-to-left-override character (`U+202E)`."
  18 
  19     # region wiki_exploit_scenario
  20     WIKI_EXPLOIT_SCENARIO = """
  21 ```solidity
  22 contract Token
  23 {
  24 
  25     address payable o; // owner
  26     mapping(address => uint) tokens;
  27 
  28     function withdraw() external returns(uint)
  29     {
  30         uint amount = tokens[msg.sender];
  31         address payable d = msg.sender;
  32         tokens[msg.sender] = 0;
  33         _withdraw(/*owner‮/*noitanitsed*/ d, o/*‭
  34 		        /*value */, amount);
  35     }
  36 
  37     function _withdraw(address payable fee_receiver, address payable destination, uint value) internal
  38     {
  39 		fee_receiver.transfer(1);
  40 		destination.transfer(value);
  41     }
  42 }
  43 ```
  44 
  45 `Token` uses the right-to-left-override character when calling `_withdraw`. As a result, the fee is incorrectly sent to `msg.sender`, and the token balance is sent to the owner.
  46 
  47 """
  48     # endregion wiki_exploit_scenario
  49 
  50     WIKI_RECOMMENDATION = "Special control characters must not be allowed."
  51 
  52     RTLO_CHARACTER_ENCODED = "\u202e".encode("utf-8")
  53     STANDARD_JSON = False
  54 
  55     def _detect(self):
  56         results = []
  57         pattern = re.compile(".*\u202e.*".encode("utf-8"))
  58 
  59         for filename, source in self.slither.source_code.items():
  60             # Attempt to find all RTLO characters in this source file.
  61             original_source_encoded = source.encode("utf-8")
  62             start_index = 0
  63 
  64             # Keep searching all file contents for the character.
  65             while True:
  66                 source_encoded = original_source_encoded[start_index:]
  67                 result_index = source_encoded.find(self.RTLO_CHARACTER_ENCODED)
  68 
  69                 # If we couldn't find the character in the remainder of source, stop.
  70                 if result_index == -1:
  71                     break
  72 
  73                 # We found another instance of the character, define our output
  74                 idx = start_index + result_index
  75 
  76                 relative = self.slither.crytic_compile.filename_lookup(filename).relative
  77                 info = f"{relative} contains a unicode right-to-left-override character at byte offset {idx}:\n"
  78 
  79                 # We have a patch, so pattern.find will return at least one result
  80 
  81                 info += f"\t- {pattern.findall(source_encoded)[0]}\n"
  82                 res = self.generate_result(info)
  83                 res.add_other(
  84                     "rtlo-character",
  85                     (filename, idx, len(self.RTLO_CHARACTER_ENCODED)),
  86                     self.compilation_unit,
  87                 )
  88                 results.append(res)
  89 
  90                 # Advance the start index for the next iteration
  91                 start_index = result_index + 1
  92 
  93         return results
  94
  [end of slither/detectors/source/rtlo.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/slither/detectors/source/rtlo.py b/slither/detectors/source/rtlo.py
  --- a/slither/detectors/source/rtlo.py
  +++ b/slither/detectors/source/rtlo.py
  @@ -88,6 +88,6 @@
                   results.append(res)
   
                   # Advance the start index for the next iteration
  -                start_index = result_index + 1
  +                start_index = idx + 1
   
           return results
  
verification_info: {"golden_diff": "diff --git a/slither/detectors/source/rtlo.py b/slither/detectors/source/rtlo.py\n--- a/slither/detectors/source/rtlo.py\n+++ b/slither/detectors/source/rtlo.py\n@@ -88,6 +88,6 @@\n                 results.append(res)\n \n                 # Advance the start index for the next iteration\n-                start_index = result_index + 1\n+                start_index = idx + 1\n \n         return results\n", "issue": "[Bug]: Infinite loop in RTLO detector\n### What happened?\n\nSlither hangs on this code indefinitely\n\n### Can you share code with us to reproduce this bug?\n\nhttps://github.com/ethereum/solidity/blob/develop/test/libsolidity/syntaxTests/comments/multiline_unicode_direction_override_5.sol\n\n### Version\n\n0.8.2\n\n### Relevant log output\n\n_No response_\n", "before_files": [{"content": "import re\nfrom slither.detectors.abstract_detector import AbstractDetector, DetectorClassification\n\n\nclass RightToLeftOverride(AbstractDetector):\n    \"\"\"\n    Detect the usage of a Right-To-Left-Override (U+202E) character\n    \"\"\"\n\n    ARGUMENT = \"rtlo\"\n    HELP = \"Right-To-Left-Override control character is used\"\n    IMPACT = DetectorClassification.HIGH\n    CONFIDENCE = DetectorClassification.HIGH\n\n    WIKI = \"https://github.com/crytic/slither/wiki/Detector-Documentation#right-to-left-override-character\"\n    WIKI_TITLE = \"Right-to-Left-Override character\"\n    WIKI_DESCRIPTION = \"An attacker can manipulate the logic of the contract by using a right-to-left-override character (`U+202E)`.\"\n\n    # region wiki_exploit_scenario\n    WIKI_EXPLOIT_SCENARIO = \"\"\"\n```solidity\ncontract Token\n{\n\n    address payable o; // owner\n    mapping(address => uint) tokens;\n\n    function withdraw() external returns(uint)\n    {\n        uint amount = tokens[msg.sender];\n        address payable d = msg.sender;\n        tokens[msg.sender] = 0;\n        _withdraw(/*owner\u202e/*noitanitsed*/ d, o/*\u202d\n\t\t        /*value */, amount);\n    }\n\n    function _withdraw(address payable fee_receiver, address payable destination, uint value) internal\n    {\n\t\tfee_receiver.transfer(1);\n\t\tdestination.transfer(value);\n    }\n}\n```\n\n`Token` uses the right-to-left-override character when calling `_withdraw`. As a result, the fee is incorrectly sent to `msg.sender`, and the token balance is sent to the owner.\n\n\"\"\"\n    # endregion wiki_exploit_scenario\n\n    WIKI_RECOMMENDATION = \"Special control characters must not be allowed.\"\n\n    RTLO_CHARACTER_ENCODED = \"\\u202e\".encode(\"utf-8\")\n    STANDARD_JSON = False\n\n    def _detect(self):\n        results = []\n        pattern = re.compile(\".*\\u202e.*\".encode(\"utf-8\"))\n\n        for filename, source in self.slither.source_code.items():\n            # Attempt to find all RTLO characters in this source file.\n            original_source_encoded = source.encode(\"utf-8\")\n            start_index = 0\n\n            # Keep searching all file contents for the character.\n            while True:\n                source_encoded = original_source_encoded[start_index:]\n                result_index = source_encoded.find(self.RTLO_CHARACTER_ENCODED)\n\n                # If we couldn't find the character in the remainder of source, stop.\n                if result_index == -1:\n                    break\n\n                # We found another instance of the character, define our output\n                idx = start_index + result_index\n\n                relative = self.slither.crytic_compile.filename_lookup(filename).relative\n                info = f\"{relative} contains a unicode right-to-left-override character at byte offset {idx}:\\n\"\n\n                # We have a patch, so pattern.find will return at least one result\n\n                info += f\"\\t- {pattern.findall(source_encoded)[0]}\\n\"\n                res = self.generate_result(info)\n                res.add_other(\n                    \"rtlo-character\",\n                    (filename, idx, len(self.RTLO_CHARACTER_ENCODED)),\n                    self.compilation_unit,\n                )\n                results.append(res)\n\n                # Advance the start index for the next iteration\n                start_index = result_index + 1\n\n        return results\n", "path": "slither/detectors/source/rtlo.py"}]}