Skip to content

Commit 6fc83d8

Browse files
author
Frank Robijn
committed
Make coderabbitai even more happy
1 parent 50263be commit 6fc83d8

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

CMake/Modules/FindNF_NativeAssemblies.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ macro(PerformSettingsForInteropEntry interopAssemblyName)
173173
list(REMOVE_DUPLICATES NF_NativeAssemblies_SOURCES)
174174

175175
# add the assembly version to the list
176-
AddNativeAssemblyVersion(interopAssemblyName interopAssemblyNameWithoutDots "${${apiNamespace}_SOURCES}")
176+
AddNativeAssemblyVersion(interopAssemblyName interopAssemblyNameWithoutDots "${${interopAssemblyName}_SOURCES}")
177177
endmacro()
178178

179179
#################################################################

targets/netcore/nanoFramework.nanoCLR.CLI/ClrInstanceOperationsProcessor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static int ProcessVerb(ClrInstanceOperationsOptions options)
6767

6868
if (options.GetNativeAssemblies)
6969
{
70-
List<NativeAssemblyDetails> nativeAssemblies = hostBuilder.GetNativeAssemblies();
70+
List<NativeAssemblyDetails>? nativeAssemblies = hostBuilder.GetNativeAssemblies();
7171
if (nativeAssemblies is not null)
7272
{
7373
if (options.GetCLRVersion)

targets/netcore/nanoFramework.nanoCLR.Host/Interop/nanoCLR.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ internal static extern void nanoCLR_SetWireProtocolTransmitCallback(
9494
internal static extern ushort nanoCLR_GetNativeAssemblyCount();
9595

9696
[DllImport(NativeLibraryName, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
97-
internal static extern void nanoCLR_GetNativeAssemblyInformation(byte[] buffer, int size);
97+
internal static extern bool nanoCLR_GetNativeAssemblyInformation(byte[] buffer, int size);
9898

9999
[DllImport("kernel32", SetLastError = true)]
100100
private static extern bool FreeLibrary(IntPtr hModule);

targets/netcore/nanoFramework.nanoCLR.Host/NanoClrHostBuilder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public nanoCLRHostBuilder UseWireProtocolPort(IPort port)
9191
public string GetCLRVersion() =>
9292
Interop.nanoCLR.nanoCLR_GetVersion();
9393

94-
public List<NativeAssemblyDetails> GetNativeAssemblies()
94+
public List<NativeAssemblyDetails>? GetNativeAssemblies()
9595
=> NativeAssemblyDetails.Get();
9696

9797
public nanoCLRHostBuilder UseSerialPortWireProtocol(string comPort) =>

targets/netcore/nanoFramework.nanoCLR.Host/NativeAssemblyDetails.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public uint CheckSum
4545
/// </summary>
4646
/// <returns>Returns a list with the metadata of native assemblies. If the runtime does
4747
/// not support this, <c>null</c> is returned.</returns>
48-
public static List<NativeAssemblyDetails> Get()
48+
public static List<NativeAssemblyDetails>? Get()
4949
{
5050
var result = new List<NativeAssemblyDetails>();
5151

@@ -64,7 +64,10 @@ public static List<NativeAssemblyDetails> Get()
6464
}
6565

6666
byte[] data = new byte[numAssemblies * /* size per assembly: */ (4 + 4 * 2 + 128 * 1)];
67-
Interop.nanoCLR.nanoCLR_GetNativeAssemblyInformation(data, data.Length);
67+
if (!Interop.nanoCLR.nanoCLR_GetNativeAssemblyInformation(data, data.Length))
68+
{
69+
return null;
70+
}
6871

6972
using var buffer = new MemoryStream(data);
7073
using var reader = new BinaryReader(buffer);

targets/netcore/nanoFramework.nanoCLR/nanoCLR_native.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,14 @@ uint16_t nanoCLR_GetNativeAssemblyCount()
188188
return g_CLR_InteropAssembliesCount;
189189
}
190190

191-
void nanoCLR_GetNativeAssemblyInformation(const CLR_UINT8 *data, size_t size)
191+
bool nanoCLR_GetNativeAssemblyInformation(const CLR_UINT8 *data, size_t size)
192192
{
193+
onst size_t requiredSize = g_CLR_InteropAssembliesCount * (sizeof(uint32_t) + 4 * sizeof(CLR_UINT16) + 128);
194+
if (size < requiredSize)
195+
{
196+
return false; // Buffer too small
197+
}
198+
193199
// clear buffer memory
194200
memset((void *)data, 0, size);
195201

@@ -214,4 +220,6 @@ void nanoCLR_GetNativeAssemblyInformation(const CLR_UINT8 *data, size_t size)
214220
hal_strcpy_s((char *)data, 128, g_CLR_InteropAssembliesNativeData[i]->m_szAssemblyName);
215221
data += 128;
216222
}
223+
224+
return true; // Success
217225
}

0 commit comments

Comments
 (0)