Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-strecker-sonarsource committed Mar 29, 2023
1 parent d382b3c commit 665ee9e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public override ProgramState[] PostProcess(SymbolicContext context)
&& createdNew.TrackedSymbol() is { } trackedCreatedNew
? new[]
{
AddLock(context, symbol).SetSymbolConstraint(trackedCreatedNew, BoolConstraint.True),
context.State.SetSymbolConstraint(trackedCreatedNew, BoolConstraint.False),
AddLock(context, objectCreation.WrappedOperation).Preserve(symbol).SetSymbolConstraint(trackedCreatedNew, BoolConstraint.True),
context.SetSymbolConstraint(trackedCreatedNew, BoolConstraint.False),
}
: AddLock(context, objectCreation.WrappedOperation).Preserve(symbol).ToArray();
}
Expand Down Expand Up @@ -198,7 +198,7 @@ private ProgramState AddLock(SymbolicContext context, ISymbol symbol)
}

lastSymbolLock[symbol] = context.Operation;
return context.SetSymbolConstraint(symbol, LockConstraint.Held).Preserve(symbol);
return context.SetSymbolConstraint(symbol, LockConstraint.Held).SetSymbolConstraint(symbol, ObjectConstraint.NotNull).Preserve(symbol);
}

private ProgramState RemoveLock(SymbolicContext context, ISymbol symbol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class MutexTest
public static void Noncompliant(MutexSecurity mutexSecurity, bool cond)
{
// Note that Dispose() closes the underlying WaitHandle, but does not release the mutex
var m0 = new Mutex(true, "foo", out var mutexWasCreated, mutexSecurity);
var m0 = new Mutex(true, "foo", out var mutexWasCreated, mutexSecurity); // Noncompliant
if (cond)
{
m0.ReleaseMutex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public void Noncompliant(Foo foo)
var m3 = Mutex.OpenExisting("x");
m3.WaitOne(); // Noncompliant

var m4 = new Mutex();

foo.instanceMutex.WaitOne(); // FN

Foo.staticMutex.WaitOne(); // Noncompliant
Expand All @@ -35,7 +33,6 @@ public void Noncompliant(Foo foo)
m1.ReleaseMutex();
m2.ReleaseMutex();
m3.ReleaseMutex();
m4.ReleaseMutex();
foo.instanceMutex.ReleaseMutex();
Foo.staticMutex.ReleaseMutex();
}
Expand Down

0 comments on commit 665ee9e

Please sign in to comment.