Author Topic: fpc compiler warnings in png decoder  (Read 302 times)

heju

  • Guest
fpc compiler warnings in png decoder
« on: 1 December 2018, 20:25:53 »
Hi,

when compiling I noticed a flood of compiler warnings similar to this one:

imzdeflate.pas(1121,40) Warning: Conversion between ordinals and pointers is not portable

Seems to originate from:

imzutil.pas

  ptr2int = uInt;
{ a pointer to integer casting is used to do pointer arithmetic.
  ptr2int must be an integer type and sizeof(ptr2int) must be less
  than sizeof(pointer) - Nomssi }

I was tempted to just change this to
  ptr2int = ptruInt;

However the comment explicitly advises to use a type smaller than sizeof(pointer).

Thanks in advance for any advice!





Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 370
    • View Profile
    • Galfar's Homepage
Re: fpc compiler warnings in png decoder
« Reply #1 on: 2 December 2018, 02:23:44 »
Hi,

I think best would be to try PtrUInt and check if there are any problems (loading and saving PNGs is where zlib is ued in Imaging).
Keep in mind that the comment is maybe 20 years old now from the times of Delphi v3 or something like that.

Quick google search found some updated zlib -> Pascal translation where"ptr2int = NativeUInt"  and in FPC "NativeUInt = PtrUInt".
Also when I look where ptr2int is used and to the original C code, it looks it's really just used to do pointer arithmetics in
old Delphi versions.


Offline heju

  • Imaging User
  • *
  • Posts: 4
    • View Profile
Re: fpc compiler warnings in png decoder
« Reply #2 on: 2 December 2018, 11:54:18 »
Hi,

thanks for the fast response!

I gave ptr2int = ptruInt; a try: No obvious problems so far.
Would there be a kind of unit test for the library to confirm everything is ok after changing such small but maybe important things?

Btw I noticed another warning, this time in the jpeg code:
I always try to test run my code using all compiler checks on. I noticed that in the jpeg code a range check error is triggered in file imjdphuff.pas

Dec(entropy^.restarts_to_go); (several occurrences, the value to be decremented is zero)

Seems to be ok if
if entropy^.restarts_to_go >0 then

is added before these lines. However I did not have a closer look if this a good idea (maybe the underflow is somehow useful?



Offline Galfar

  • Administrator
  • Imaging User
  • *****
  • Posts: 370
    • View Profile
    • Galfar's Homepage
Re: fpc compiler warnings in png decoder
« Reply #3 on: 21 January 2019, 14:50:39 »
"if entropy^.restarts_to_go >0 then" in imjdhuff.pas is safe.
I had it in Imaging branch used in my Deskew tool for years and probably
forgot to merge it to the main branch.

I also did tests with "ptr2int = ptruInt" for zlib and everything was fine
so I pushed both changes to the repository.