Skip to content

Commit de87dd5

Browse files
committed
Test no result if deferred function returns error
1 parent 57dafd3 commit de87dd5

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

go/ql/test/query-tests/InconsistentCode/UnhandledCloseWritableHandle/UnhandledCloseWritableHandle.expected

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ edges
66
| tests.go:31:5:31:78 | ... := ...[0] | tests.go:33:29:33:29 | f |
77
| tests.go:32:21:32:21 | f | tests.go:8:24:8:24 | definition of f |
88
| tests.go:33:29:33:29 | f | tests.go:12:32:12:32 | definition of f |
9-
| tests.go:43:5:43:76 | ... := ...[0] | tests.go:44:21:44:21 | f |
10-
| tests.go:43:5:43:76 | ... := ...[0] | tests.go:45:29:45:29 | f |
11-
| tests.go:44:21:44:21 | f | tests.go:8:24:8:24 | definition of f |
12-
| tests.go:45:29:45:29 | f | tests.go:12:32:12:32 | definition of f |
13-
| tests.go:51:5:51:78 | ... := ...[0] | tests.go:53:3:53:3 | f |
14-
| tests.go:63:5:63:76 | ... := ...[0] | tests.go:65:3:65:3 | f |
15-
| tests.go:105:5:105:78 | ... := ...[0] | tests.go:107:9:107:9 | f |
16-
| tests.go:122:5:122:78 | ... := ...[0] | tests.go:126:3:126:3 | f |
9+
| tests.go:45:5:45:76 | ... := ...[0] | tests.go:46:21:46:21 | f |
10+
| tests.go:45:5:45:76 | ... := ...[0] | tests.go:47:29:47:29 | f |
11+
| tests.go:46:21:46:21 | f | tests.go:8:24:8:24 | definition of f |
12+
| tests.go:47:29:47:29 | f | tests.go:12:32:12:32 | definition of f |
13+
| tests.go:54:5:54:78 | ... := ...[0] | tests.go:56:3:56:3 | f |
14+
| tests.go:66:5:66:76 | ... := ...[0] | tests.go:68:3:68:3 | f |
15+
| tests.go:108:5:108:78 | ... := ...[0] | tests.go:110:9:110:9 | f |
16+
| tests.go:125:5:125:78 | ... := ...[0] | tests.go:129:3:129:3 | f |
1717
nodes
1818
| tests.go:8:24:8:24 | definition of f | semmle.label | definition of f |
1919
| tests.go:9:8:9:8 | f | semmle.label | f |
@@ -23,24 +23,24 @@ nodes
2323
| tests.go:31:5:31:78 | ... := ...[0] | semmle.label | ... := ...[0] |
2424
| tests.go:32:21:32:21 | f | semmle.label | f |
2525
| tests.go:33:29:33:29 | f | semmle.label | f |
26-
| tests.go:43:5:43:76 | ... := ...[0] | semmle.label | ... := ...[0] |
27-
| tests.go:44:21:44:21 | f | semmle.label | f |
28-
| tests.go:45:29:45:29 | f | semmle.label | f |
29-
| tests.go:51:5:51:78 | ... := ...[0] | semmle.label | ... := ...[0] |
30-
| tests.go:53:3:53:3 | f | semmle.label | f |
31-
| tests.go:63:5:63:76 | ... := ...[0] | semmle.label | ... := ...[0] |
32-
| tests.go:65:3:65:3 | f | semmle.label | f |
33-
| tests.go:105:5:105:78 | ... := ...[0] | semmle.label | ... := ...[0] |
34-
| tests.go:107:9:107:9 | f | semmle.label | f |
35-
| tests.go:122:5:122:78 | ... := ...[0] | semmle.label | ... := ...[0] |
36-
| tests.go:126:3:126:3 | f | semmle.label | f |
26+
| tests.go:45:5:45:76 | ... := ...[0] | semmle.label | ... := ...[0] |
27+
| tests.go:46:21:46:21 | f | semmle.label | f |
28+
| tests.go:47:29:47:29 | f | semmle.label | f |
29+
| tests.go:54:5:54:78 | ... := ...[0] | semmle.label | ... := ...[0] |
30+
| tests.go:56:3:56:3 | f | semmle.label | f |
31+
| tests.go:66:5:66:76 | ... := ...[0] | semmle.label | ... := ...[0] |
32+
| tests.go:68:3:68:3 | f | semmle.label | f |
33+
| tests.go:108:5:108:78 | ... := ...[0] | semmle.label | ... := ...[0] |
34+
| tests.go:110:9:110:9 | f | semmle.label | f |
35+
| tests.go:125:5:125:78 | ... := ...[0] | semmle.label | ... := ...[0] |
36+
| tests.go:129:3:129:3 | f | semmle.label | f |
3737
subpaths
3838
#select
3939
| tests.go:9:8:9:8 | f | tests.go:31:5:31:78 | ... := ...[0] | tests.go:9:8:9:8 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:31:15:31:78 | call to OpenFile | call to OpenFile |
40-
| tests.go:9:8:9:8 | f | tests.go:43:5:43:76 | ... := ...[0] | tests.go:9:8:9:8 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:43:15:43:76 | call to OpenFile | call to OpenFile |
40+
| tests.go:9:8:9:8 | f | tests.go:45:5:45:76 | ... := ...[0] | tests.go:9:8:9:8 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:45:15:45:76 | call to OpenFile | call to OpenFile |
4141
| tests.go:14:3:14:3 | f | tests.go:31:5:31:78 | ... := ...[0] | tests.go:14:3:14:3 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:31:15:31:78 | call to OpenFile | call to OpenFile |
42-
| tests.go:14:3:14:3 | f | tests.go:43:5:43:76 | ... := ...[0] | tests.go:14:3:14:3 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:43:15:43:76 | call to OpenFile | call to OpenFile |
43-
| tests.go:53:3:53:3 | f | tests.go:51:5:51:78 | ... := ...[0] | tests.go:53:3:53:3 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:51:15:51:78 | call to OpenFile | call to OpenFile |
44-
| tests.go:65:3:65:3 | f | tests.go:63:5:63:76 | ... := ...[0] | tests.go:65:3:65:3 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:63:15:63:76 | call to OpenFile | call to OpenFile |
45-
| tests.go:107:9:107:9 | f | tests.go:105:5:105:78 | ... := ...[0] | tests.go:107:9:107:9 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:105:15:105:78 | call to OpenFile | call to OpenFile |
46-
| tests.go:126:3:126:3 | f | tests.go:122:5:122:78 | ... := ...[0] | tests.go:126:3:126:3 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:122:15:122:78 | call to OpenFile | call to OpenFile |
42+
| tests.go:14:3:14:3 | f | tests.go:45:5:45:76 | ... := ...[0] | tests.go:14:3:14:3 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:45:15:45:76 | call to OpenFile | call to OpenFile |
43+
| tests.go:56:3:56:3 | f | tests.go:54:5:54:78 | ... := ...[0] | tests.go:56:3:56:3 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:54:15:54:78 | call to OpenFile | call to OpenFile |
44+
| tests.go:68:3:68:3 | f | tests.go:66:5:66:76 | ... := ...[0] | tests.go:68:3:68:3 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:66:15:66:76 | call to OpenFile | call to OpenFile |
45+
| tests.go:110:9:110:9 | f | tests.go:108:5:108:78 | ... := ...[0] | tests.go:110:9:110:9 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:108:15:108:78 | call to OpenFile | call to OpenFile |
46+
| tests.go:129:3:129:3 | f | tests.go:125:5:125:78 | ... := ...[0] | tests.go:129:3:129:3 | f | File handle may be writable as a result of data flow from a $@ and closing it may result in data loss upon failure, which is not handled explicitly. | tests.go:125:15:125:78 | call to OpenFile | call to OpenFile |

go/ql/test/query-tests/InconsistentCode/UnhandledCloseWritableHandle/tests.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,21 @@ func deferredCalls() {
3131
if f, err := os.OpenFile("foo.txt", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0666); err != nil {
3232
closeFileDeferred(f) // NOT OK
3333
closeFileDeferredIndirect(f) // NOT OK
34+
closeFileDeferredIndirectReturn(f)
3435
}
3536

3637
// open file for reading
3738
if f, err := os.OpenFile("foo.txt", os.O_RDONLY|os.O_CREATE, 0666); err != nil {
3839
closeFileDeferred(f) // OK
3940
closeFileDeferredIndirect(f) // OK
41+
closeFileDeferredIndirectReturn(f)
4042
}
4143

4244
// open file for reading and writing
4345
if f, err := os.OpenFile("foo.txt", os.O_RDWR|os.O_TRUNC|os.O_CREATE, 0666); err != nil {
4446
closeFileDeferred(f) // NOT OK
4547
closeFileDeferredIndirect(f) // NOT OK
48+
closeFileDeferredIndirectReturn(f)
4649
}
4750
}
4851

0 commit comments

Comments
 (0)