Skip to content

Commit 4546d8f

Browse files
committed
C#: Base API Abuse/UncheckedReturnValue test case on stubs, clean up test and update expected output.
1 parent ada49db commit 4546d8f

File tree

3 files changed

+10
-32
lines changed

3 files changed

+10
-32
lines changed

csharp/ql/test/query-tests/API Abuse/UncheckedReturnValue/UncheckedReturnValue.cs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
using System;
2-
class HashSet<T>
3-
{
4-
public bool Add(T t)
5-
{
6-
return true;
7-
}
8-
}
2+
using System.Text;
3+
using System.Collections.Generic;
94

105
class C1
116
{
@@ -30,11 +25,6 @@ static void Main(string[] args)
3025
}
3126
}
3227

33-
class StringBuilder
34-
{
35-
public StringBuilder Append(string s) { return this; }
36-
}
37-
3828
class C2
3929
{
4030
static void Main(string[] args)
@@ -59,20 +49,6 @@ static void Main(string[] args)
5949
}
6050
}
6151

62-
namespace System.IO
63-
{
64-
public abstract class Stream
65-
{
66-
public abstract int Read(byte[] buffer, int offset, int count);
67-
public virtual int ReadByte() { return 0; }
68-
}
69-
70-
public class MemoryStream : Stream
71-
{
72-
public override int Read(byte[] buffer, int offset, int count) { return 0; }
73-
}
74-
}
75-
7652
class C3
7753
{
7854
static void Main(string[] args)
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
| UncheckedReturnValue.cs:29:9:29:31 | call to method Add | Result of call to 'Add' is ignored, but 90% of calls to this method have their result used. |
2-
| UncheckedReturnValue.cs:91:9:91:26 | call to method Read | Result of call to 'Read' is ignored, but should always be checked. |
3-
| UncheckedReturnValue.cs:92:9:92:20 | call to method ReadByte | Result of call to 'ReadByte' is ignored, but should always be checked. |
4-
| UncheckedReturnValue.cs:109:9:109:17 | call to method M1<Int32> | Result of call to 'M1<Int32>' is ignored, but 90% of calls to this method have their result used. |
5-
| UncheckedReturnValue.cs:130:9:130:21 | call to method M2<Decimal> | Result of call to 'M2<Decimal>' is ignored, but 90% of calls to this method have their result used. |
6-
| UncheckedReturnValue.cs:142:9:142:20 | call to method M3<C6> | Result of call to 'M3<C6>' is ignored, but 90% of calls to this method have their result used. |
1+
| UncheckedReturnValue.cs:24:9:24:31 | call to method Add | Result of call to 'Add' is ignored, but 90% of calls to this method have their result used. |
2+
| UncheckedReturnValue.cs:67:9:67:26 | call to method Read | Result of call to 'Read' is ignored, but should always be checked. |
3+
| UncheckedReturnValue.cs:68:9:68:20 | call to method ReadByte | Result of call to 'ReadByte' is ignored, but should always be checked. |
4+
| UncheckedReturnValue.cs:85:9:85:17 | call to method M1<Int32> | Result of call to 'M1<Int32>' is ignored, but 90% of calls to this method have their result used. |
5+
| UncheckedReturnValue.cs:106:9:106:21 | call to method M2<Decimal> | Result of call to 'M2<Decimal>' is ignored, but 90% of calls to this method have their result used. |
6+
| UncheckedReturnValue.cs:118:9:118:20 | call to method M3<C6> | Result of call to 'M3<C6>' is ignored, but 90% of calls to this method have their result used. |
77
| UncheckedReturnValueBad.cs:29:9:29:20 | call to method DoPrint | Result of call to 'DoPrint' is ignored, but 90% of calls to this method have their result used. |
88
| UncheckedReturnValueBad.cs:36:13:36:40 | call to method Read | Result of call to 'Read' is ignored, but should always be checked. |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
semmle-extractor-options: /nostdlib /noconfig
2+
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../resources/stubs/_frameworks/Microsoft.NETCore.App/Microsoft.NETCore.App.csproj

0 commit comments

Comments
 (0)