Skip to content

Commit

Permalink
Fix null-related build warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
RedFlames committed Jul 20, 2024
1 parent c994b96 commit 32b40f5
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 31 deletions.
4 changes: 2 additions & 2 deletions CelesteNet.Client/CelesteNetClientSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -784,15 +784,15 @@ public TextMenu.Slider CreateMenuSlider(TextMenu menu, string dialogLabel, int m
return item;
}

public TextMenu.Button CreateMenuButton(TextMenu menu, string dialogLabel, Func<string, string>? dialogTransform, Action onPress)
public TextMenu.Button CreateMenuButton(TextMenu menu, string dialogLabel, Func<string, string> dialogTransform, Action onPress)
{
string label = $"modoptions_celestenetclient_{dialogLabel}".DialogClean();
TextMenu.Button item = new TextMenu.Button(dialogTransform?.Invoke(label) ?? label);
item.Pressed(onPress);
menu.Add(item);
return item;
}
public TextMenu.Button CreateMenuStringInput(TextMenu menu, string dialogLabel, Func<string, string>? dialogTransform, int maxValueLength, Func<string> currentValue, Action<string> newValue) {
public TextMenu.Button CreateMenuStringInput(TextMenu menu, string dialogLabel, Func<string, string> dialogTransform, int maxValueLength, Func<string> currentValue, Action<string> newValue) {
string label = $"modoptions_celestenetclient_{dialogLabel}".DialogClean();
TextMenu.Button item = new TextMenu.Button(dialogTransform?.Invoke(label) ?? label);
item.Pressed(() => {
Expand Down
4 changes: 2 additions & 2 deletions CelesteNet.Client/Components/CelesteNetChatComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ public enum ChatMode {
Off
}

public MTexture? InputScrollUpIcon;
public MTexture? InputScrollDownIcon;
public MTexture InputScrollUpIcon;
public MTexture InputScrollDownIcon;
public MTexture ArrowUpIcon => GFX.Gui["controls/directions/0x-1"];
public MTexture ArrowDownIcon => GFX.Gui["controls/directions/0x1"];
private bool activeController = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ private string ClientInfoGet(string inp) {

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private NetworkInterface FindInternetFacingNic() {
IPAddress? addrInternet = null;
IPAddress addrInternet = null;
Socket socket = new(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
try {
socket.Connect("8.8.8.8", 80);
Expand Down
4 changes: 2 additions & 2 deletions CelesteNet.Client/Handshake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public static class Handshake {

// Read the "HTTP" response
string statusLine = netStream.UnbufferedReadLine();
string[] statusSegs = statusLine.Split(new[] { ' ' }, 3);
if (statusSegs.Length != 3)
string[] statusSegs = statusLine?.Split(new[] { ' ' }, 3);
if (statusSegs?.Length != 3)
throw new InvalidDataException($"Invalid HTTP response status line: '{statusLine}'");
int statusCode = int.Parse(statusSegs[1]);

Expand Down
2 changes: 1 addition & 1 deletion CelesteNet.Server.FrontendModule/RCEPs/RCEPControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ public static void ProcessAllAvatars(Frontend f, HttpRequestEventArgs c) {

try {
info = Image.Identify(data);
} catch (UnknownImageFormatException e) {
} catch (UnknownImageFormatException) {
Logger.Log(LogLevel.INF, "frontend", $"Could not identify avatar: {uid}");
continue;
}
Expand Down
11 changes: 5 additions & 6 deletions CelesteNet.Server.SqliteModule/MessagePackHelper.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using Microsoft.Xna.Framework;
using System;
using System;
using System.Collections.Generic;
using MessagePack;
using MessagePack.Formatters;
using MessagePack.Resolvers;
using Microsoft.Xna.Framework;

namespace Celeste.Mod.CelesteNet.Server.Sqlite
{
namespace Celeste.Mod.CelesteNet.Server.Sqlite {
public static class MessagePackHelper {

public static readonly MessagePackSerializerOptions Options = ContractlessStandardResolver.Options
Expand All @@ -29,12 +28,12 @@ public class CelesteNetMessagePackResolver : IFormatterResolver {
private CelesteNetMessagePackResolver() {
}

public IMessagePackFormatter<T> GetFormatter<T>()
public IMessagePackFormatter<T>? GetFormatter<T>()
=> Cache<T>.Formatter;

private static class Cache<T> {

public static IMessagePackFormatter<T> Formatter;
public static IMessagePackFormatter<T>? Formatter;

static Cache() {
if (Formatters.TryGetValue(typeof(T), out object? fo)) {
Expand Down
50 changes: 35 additions & 15 deletions CelesteNet.Server.SqliteModule/SqliteUserData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ FROM sqlite_master
{ "$real", real },
{ "$type", typename },
};
return mini.Run<string>().value;
return mini.Run<string>().value ?? "";

} else {
using MiniCommand mini = new(this) {
Expand Down Expand Up @@ -182,7 +182,7 @@ FROM sqlite_master
",
{ "$name", name },
};
return mini.Run<string>().value;
return mini.Run<string>().value ?? "";

} else {
using MiniCommand mini = new(this) {
Expand Down Expand Up @@ -226,7 +226,7 @@ FROM sqlite_master
{ "$name", name },
{ "$real", real },
};
return mini.Run<string>().value;
return mini.Run<string>().value ?? "";

} else {
using MiniCommand mini = new(this) {
Expand Down Expand Up @@ -401,9 +401,14 @@ FROM [{table}]
{ "$format", (int) DataFormat.MessagePack },
{ "$length", ms.Length },
};
(SqliteConnection con, SqliteCommand cmd) = mini.Run(out long rowid);
(SqliteConnection con, SqliteCommand cmd) = mini.Run(out long? rowid);

using SqliteBlob blob = new(con, table, "value", rowid);
if (rowid == null) {
Logger.Log(LogLevel.ERR, "sqlite", $"Save<T>: Failed getting rowid for {table} of UID {uid}");
return;
}

using SqliteBlob blob = new(con, table, "value", (long) rowid);
ms.CopyTo(blob);
blob.Dispose();
}
Expand All @@ -428,9 +433,14 @@ FROM [{table}]
{ "$uid", uid },
{ "$length", ms.Length },
};
(SqliteConnection con, SqliteCommand cmd) = mini.Run(out long rowid);
(SqliteConnection con, SqliteCommand cmd) = mini.Run(out long? rowid);

if (rowid == null) {
Logger.Log(LogLevel.ERR, "sqlite", $"WriteFile: Failed getting rowid for {table} of UID {uid}");
return;
}

using SqliteBlob blob = new(con, table, "value", rowid);
using SqliteBlob blob = new(con, table, "value", (long) rowid);
ms.CopyTo(blob);
blob.Dispose();
});
Expand Down Expand Up @@ -874,9 +884,14 @@ FROM [{table}]
{ "$format", (int) format },
{ "$length", ms.Length },
};
(SqliteConnection con, SqliteCommand cmd) = mini.Run(out long rowid);
(SqliteConnection con, SqliteCommand cmd) = mini.Run(out long? rowid);

if (rowid == null) {
Logger.Log(LogLevel.ERR, "sqlite", $"InsertData: Failed getting rowid for {table} of UID {uid}");
return;
}

using SqliteBlob blob = new(con, table, "value", rowid);
using SqliteBlob blob = new(con, table, "value", (long) rowid);
ms.CopyTo(blob);
blob.Dispose();
}
Expand All @@ -902,9 +917,14 @@ FROM [{table}]
{ "$uid", uid },
{ "$length", ms.Length },
};
(SqliteConnection con, SqliteCommand cmd) = mini.Run(out long rowid);
(SqliteConnection con, SqliteCommand cmd) = mini.Run(out long? rowid);

if (rowid == null) {
Logger.Log(LogLevel.ERR, "sqlite", $"InsertFile: Failed getting rowid for {table} of UID {uid}");
return;
}

using SqliteBlob blob = new(con, table, "value", rowid);
using SqliteBlob blob = new(con, table, "value", (long) rowid);
ms.CopyTo(blob);
blob.Dispose();
}
Expand Down Expand Up @@ -1298,14 +1318,14 @@ public void Next(MiniCommand cmd) {
return (con, cmd, cmd.ExecuteNonQuery());
}

public (SqliteConnection con, SqliteCommand cmd, T value) Run<T>() {
public (SqliteConnection con, SqliteCommand cmd, T? value) Run<T>() {
(SqliteConnection con, SqliteCommand cmd) = Prepare();
return (con, cmd, (T) cmd.ExecuteScalar());
return (con, cmd, (T?) cmd.ExecuteScalar());
}

public (SqliteConnection con, SqliteCommand cmd) Run<T>(out T value) {
public (SqliteConnection con, SqliteCommand cmd) Run<T>(out T? value) {
(SqliteConnection con, SqliteCommand cmd) = Prepare();
value = (T) cmd.ExecuteScalar();
value = (T?) cmd.ExecuteScalar();
return (con, cmd);
}

Expand Down
2 changes: 1 addition & 1 deletion CelesteNet.Shared/CelesteNetUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ public static bool IsDisconnect(this SocketException se) {
}
}

public static string UnbufferedReadLine(this NetworkStream netStream) {
public static string? UnbufferedReadLine(this NetworkStream netStream) {
//Unbuffered "read line" implementation reading every byte one at a time
//Extremely slow and inefficient, but otherwise we may gobble up binary packet bytes by accident :catresort:
List<byte> lineChars = new List<byte>();
Expand Down
2 changes: 1 addition & 1 deletion CelesteNet.Shared/DataTypes/DataClientInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static DataClientInfoRequest() {

public uint ID = uint.MaxValue;

public string Nonce;
public string Nonce = "";

public string[] List = Dummy<string>.EmptyArray;
public string[] MapStrings = Dummy<string>.EmptyArray;
Expand Down

0 comments on commit 32b40f5

Please sign in to comment.