mirror of
https://github.com/S7NetPlus/s7netplus.git
synced 2026-02-17 22:38:27 +08:00
Merge pull request #308 from scamille/fb-fixWarnings
Fix some null deref warnings.
This commit is contained in:
@@ -13,6 +13,10 @@ namespace S7.Net.Protocol
|
||||
|
||||
public static byte[] SerializeDataItem(DataItem dataItem)
|
||||
{
|
||||
if (dataItem.Value == null)
|
||||
{
|
||||
throw new Exception($"DataItem.Value is null, cannot serialize. StartAddr={dataItem.StartByteAdr} VarType={dataItem.VarType}");
|
||||
}
|
||||
if (dataItem.Value is string s)
|
||||
return dataItem.VarType == VarType.StringEx
|
||||
? StringEx.ToByteArray(s, dataItem.Count)
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace S7.Net.Types
|
||||
/// <summary>
|
||||
/// Converts an array of T repesented as S7 binary data to an array of T
|
||||
/// </summary>
|
||||
public static T[] ToArray<T>(byte[] bytes, Func<byte[], T> converter)
|
||||
public static T[] ToArray<T>(byte[] bytes, Func<byte[], T> converter) where T : struct
|
||||
{
|
||||
var typeSize = Marshal.SizeOf(default(T));
|
||||
var entries = bytes.Length / typeSize;
|
||||
|
||||
Reference in New Issue
Block a user