FreeImage wrapper Parameter Bug: incorrect parameter indexing in FI_ALLOCATET

57 views
Skip to first unread message

Grigory Filatov

unread,
Aug 9, 2025, 5:25:40 AMAug 9
to Harbour Developers
Hi there,

To whow it may concern.

FI_ALLOCATET() function use the same parameter index (hb_parni(3)) for both height and bpp, which is a bug and will cause incorrect behavior.

Recommendation: Fix the parameter index bug in FI_ALLOCATET (e.g., use hb_parni(4) for bpp).

Corrected code is below:

HB_FUNC( FI_ALLOCATET )
{
   if( HB_ISNUM( 1 ) && HB_ISNUM( 2 ) && HB_ISNUM( 3 ) )
   {
      FREE_IMAGE_TYPE   type = ( FREE_IMAGE_TYPE ) hb_parni( 1 );
      int               width = hb_parni( 2 );
      int               height = hb_parni( 3 );
      int               bpp = hb_parni( 4 );
      unsigned          red_mask = ( unsigned ) hb_parni( 5 );
      unsigned          green_mask = ( unsigned ) hb_parni( 6 );
      unsigned          blue_mask = ( unsigned ) hb_parni( 7 );

      hb_FIBITMAP_ret( FreeImage_AllocateT( type, width, height, bpp, red_mask, green_mask, blue_mask ), HB_TRUE );
   }
   else
   {
      hb_errRT_BASE_SubstR( EG_ARG, 0, NULL, HB_ERR_FUNCNAME, HB_ERR_ARGS_BASEPARAMS );
   }
}

Best regards,

Grigory Filatov

Reply all
Reply to author
Forward
0 new messages