• Welcome to Vampyre Imaging Library Forum. Please login or sign up.
 

fpc compiler warnings in png decoder

Started by heju, 1 December 2018, 20:25:53

Previous topic - Next topic

heju

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!





Galfar

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.


heju

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?



Galfar

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

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Name:
Email:

Shortcuts: ALT+S save/post or ALT+P preview

SMF spam blocked by CleanTalk