Skip to content

Conditional in unsafe code prints (IntPtr) casts where nint was used #4137

Description

@siegfriedpammer

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.Methods

Erroneous output

Current master (dbf23c6) 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 (6fcb387) 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 (dbf23c6); measured at 6fcb387 against merge base
    712ad1a, over the top-200 nuget.org packages. One type in the corpus is affected.

Filed by an AI agent (Claude) on Siegfried's behalf.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DecompilerThe decompiler engine itselfOutputOutput code formatting; hyperlinks/tooltips on output code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions