File size: 5,168 Bytes
1588266
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
{
  "easy": {
    "null_check": {
      "type": "ast",
      "bug_type": "null_check",
      "oracle_hint": "Add back the if-guard that was removed"
    },
    "simple_typo": {
      "type": "ast",
      "bug_type": "simple_typo",
      "oracle_hint": "Fix the misspelled variable name"
    },
    "string_index": {
      "type": "ast",
      "bug_type": "string_index",
      "oracle_hint": "Correct the index offset"
    },
    "default_value": {
      "type": "ast",
      "bug_type": "default_value",
      "oracle_hint": "Restore dict.get() with proper default"
    },
    "empty_return": {
      "type": "ast",
      "bug_type": "empty_return",
      "oracle_hint": "Remove the premature return None"
    }
  },
  "medium": {
    "off_by_one": {
      "type": "ast",
      "bug_type": "off_by_one"
    },
    "loop_skip": {
      "type": "ast",
      "bug_type": "loop_skip"
    },
    "sign_error": {
      "type": "ast",
      "bug_type": "sign_error"
    },
    "swap_args": {
      "type": "ast",
      "bug_type": "swap_args"
    },
    "uninitialised_var": {
      "type": "ast",
      "bug_type": "uninitialised_var"
    }
  },
  "hard": {
    "division_by_zero_empty": {
      "type": "ast",
      "bug_type": "division_by_zero_empty"
    },
    "division_by_zero_zero": {
      "type": "ast",
      "bug_type": "division_by_zero_zero"
    },
    "float_precision": {
      "type": "ast",
      "bug_type": "float_precision"
    },
    "abs_usage": {
      "type": "ast",
      "bug_type": "abs_usage"
    },
    "round_error": {
      "type": "ast",
      "bug_type": "round_error"
    }
  },
  "harder": {
    "missing_lock": {
      "type": "template",
      "buggy": "counter = 0\ndef increment():\n    global counter\n    counter += 1",
      "oracle": "counter = 0\nimport threading\nlock = threading.Lock()\ndef increment():\n    global counter\n    with lock:\n        counter += 1"
    },
    "double_lock": {
      "type": "template",
      "buggy": "import threading\nlock = threading.Lock()\ndef do_work():\n    lock.acquire()\n    lock.acquire()\n    print('working')\n    lock.release()",
      "oracle": "import threading\nlock = threading.Lock()\ndef do_work():\n    with lock:\n        print('working')"
    },
    "global_nonatomic": {
      "type": "template",
      "buggy": "count = 0\ndef add():\n    global count\n    count = count + 1",
      "oracle": "count = 0\ndef add():\n    global count\n    count += 1"
    },
    "thread_safe_list": {
      "type": "template",
      "buggy": "import threading\nitems = []\ndef append_item(item):\n    items.append(item)",
      "oracle": "import threading\nitems = []\nlock = threading.Lock()\ndef append_item(item):\n    with lock:\n        items.append(item)"
    },
    "volatile_read": {
      "type": "template",
      "buggy": "import threading\nstop = False\ndef worker():\n    while not stop:\n        pass",
      "oracle": "import threading\nstop = False\nlock = threading.Lock()\ndef worker():\n    while True:\n        with lock:\n            if stop:\n                break"
    }
  },
  "hardest": {
    "deadlock_order": {
      "type": "template",
      "buggy": "import threading\nlock1 = threading.Lock()\nlock2 = threading.Lock()\ndef thread1():\n    with lock1:\n        with lock2:\n            pass\ndef thread2():\n    with lock2:\n        with lock1:\n            pass",
      "oracle": "import threading\nlock1 = threading.Lock()\nlock2 = threading.Lock()\ndef thread1():\n    with lock1:\n        with lock2:\n            pass\ndef thread2():\n    with lock1:\n        with lock2:\n            pass"
    },
    "nested_lock_timeout": {
      "type": "template",
      "buggy": "import threading\nlock = threading.Lock()\ndef work():\n    lock.acquire()\n    # critical section\n    lock.release()",
      "oracle": "import threading\nlock = threading.Lock()\ndef work():\n    if lock.acquire(timeout=1):\n        try:\n            # critical section\n        finally:\n            lock.release()"
    },
    "fork_join": {
      "type": "template",
      "buggy": "import threading\ndef worker():\n    pass\nt = threading.Thread(target=worker)\nt.start()",
      "oracle": "import threading\ndef worker():\n    pass\nt = threading.Thread(target=worker)\nt.start()\nt.join()"
    },
    "mutex_release": {
      "type": "template",
      "buggy": "import threading\nlock = threading.Lock()\ndef thread_A():\n    lock.acquire()\n    lock.release()\ndef thread_B():\n    lock.release()",
      "oracle": "import threading\nlock = threading.Lock()\ndef thread_A():\n    with lock:\n        pass\ndef thread_B():\n    with lock:\n        pass"
    },
    "race_on_init": {
      "type": "template",
      "buggy": "import threading\nitems = []\ndef init():\n    global items\n    items = [1,2,3]\nt = threading.Thread(target=init)\nt.start()\nprint(items)",
      "oracle": "import threading\nitems = []\ndef init():\n    global items\n    items = [1,2,3]\nt = threading.Thread(target=init)\nt.start()\nt.join()\nprint(items)"
    }
  }
}