C#: Base API Abuse/UncheckedReturnValue test case on stubs, clean up test and update expected output.

This commit is contained in:
Michael Nebel
2023-06-21 09:10:08 +02:00
parent ada49dbb2c
commit 4546d8f0bf
3 changed files with 10 additions and 32 deletions

View File

@@ -1,11 +1,6 @@
using System;
class HashSet<T>
{
public bool Add(T t)
{
return true;
}
}
using System.Text;
using System.Collections.Generic;
class C1
{
@@ -30,11 +25,6 @@ class C1
}
}
class StringBuilder
{
public StringBuilder Append(string s) { return this; }
}
class C2
{
static void Main(string[] args)
@@ -59,20 +49,6 @@ class C2
}
}
namespace System.IO
{
public abstract class Stream
{
public abstract int Read(byte[] buffer, int offset, int count);
public virtual int ReadByte() { return 0; }
}
public class MemoryStream : Stream
{
public override int Read(byte[] buffer, int offset, int count) { return 0; }
}
}
class C3
{
static void Main(string[] args)

View File

@@ -1,8 +1,8 @@
| 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. |
| UncheckedReturnValue.cs:91:9:91:26 | call to method Read | Result of call to 'Read' is ignored, but should always be checked. |
| UncheckedReturnValue.cs:92:9:92:20 | call to method ReadByte | Result of call to 'ReadByte' is ignored, but should always be checked. |
| 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. |
| 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. |
| 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. |
| 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. |
| UncheckedReturnValue.cs:67:9:67:26 | call to method Read | Result of call to 'Read' is ignored, but should always be checked. |
| UncheckedReturnValue.cs:68:9:68:20 | call to method ReadByte | Result of call to 'ReadByte' is ignored, but should always be checked. |
| 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. |
| 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. |
| 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. |
| 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. |
| UncheckedReturnValueBad.cs:36:13:36:40 | call to method Read | Result of call to 'Read' is ignored, but should always be checked. |

View File

@@ -0,0 +1,2 @@
semmle-extractor-options: /nostdlib /noconfig
semmle-extractor-options: --load-sources-from-project:${testdir}/../../../resources/stubs/_frameworks/Microsoft.NETCore.App/Microsoft.NETCore.App.csproj