Conditional in unsafe code prints (IntPtr) casts where nint was used
Author: siegfriedpammerCreated Sep 13, 2026Updated Sep 13, 2026
LabelsDecompilerOutput
Input code
SharpCompress 1.0.0, SharpCompress.Compressors.ZStandard.Unsafe.Methods (the ZSTD_decompressStream
region), decompiled with unsafe code and native integers enabled:
ilspycmd ~/.cache/nugetfuzz/sharpcompress/1.0.0/lib/net10.0/SharpCompress.dll \
-t SharpCompress.Compressors.ZStandard.Unsafe.MethodsErroneous output
Current master (dbf23c6e4) uses nint throughout:
return (nuint)((((nuint)((zds->format == ZSTD_format_e.ZSTD_f_zstd1) ? 6 : 2) > num7)
? ((nint)((zds->format == ZSTD_format_e.ZSTD_f_zstd1) ? 6 : 2))
: ((nint)num7)) - (nint)zds->lhSize + 3);With #4091 (6fcb387ff) the branches are cast to IntPtr instead, and one of them keeps the nint
cast underneath:
return (nuint)((nint)(((nuint)((zds->format == ZSTD_format_e.ZSTD_f_zstd1) ? 6 : 2) > num7)
? ((IntPtr)((zds->format == ZSTD_format_e.ZSTD_f_zstd1) ? 6 : 2))
: ((IntPtr)(nint)num7)) - (nint)zds->lhSize + 3);Same type either way, so this is readability only: with the native-integer setting on, the
conditional should keep printing nint rather than falling back to IntPtr.
Details
- Product in use: ICSharpCode.Decompiler, built from source
- Version in use: not reproducible on master (dbf23c6e4); measured at 6fcb387ff against merge base 712ad1aed, over the top-200 nuget.org packages. One type in the corpus is affected.
Filed by an AI agent (Claude) on Siegfried's behalf.
Source: icsharpcode/ILSpy