pst-format / libpst

library for reading Microsoft Outlook PST files
GNU General Public License v2.0
16 stars 4 forks source link

build: Fix 'incompatible pointer types' warning on i686 #11

Closed mcrha closed 7 months ago

mcrha commented 7 months ago

This fixes a recent Fedora build, which failed on i686 architecture with "incompatible pointer types" error:

libpst.c: In function 'pst_read_block_size':
libpst.c:3832:36: error: passing argument 2 of 'uncompress' from incompatible pointer type [-Wincompatible-pointer-types]
 3832 |     if (uncompress((Bytef *) *buf, &result_size, (Bytef *) zbuf, size) != Z_OK || result_size != inflated_size) {
      |                                    ^~~~~~~~~~~~
      |                                    |
      |                                    size_t * {aka unsigned int *}
In file included from libpst.c:9:
/usr/include/zlib.h:1251:70: note: expected 'long unsigned int *' but argument is of type 'size_t *' {aka 'unsigned int *'}
 1251 | Z_EXTERN int Z_EXPORT uncompress(unsigned char *dest, unsigned long *destLen, const unsigned char *source, unsigned long sourceLen);
      |                                                       ~~~~~~~~~~~~~~~^~~~~~~
pabs3 commented 7 months ago

This change will cause the wrong printf format specifier to be used in the following DEBUG_WARN call after uncompress failure.

Also, I think it would be best to use the zlib uLongf type to make it explicit that this is a variable for zlib rather than libpst, just as the casts in the call to uncompress do for Bytef.

Please add info about the commit you are fixing to the commit message:

Fixes: commit a9fb0d8c21c781e679e6e93bb24da14b620ce60d

-- bye, pabs

https://bonedaddy.net/pabs3/

mcrha commented 7 months ago

This change will cause the wrong printf format specifier to be used in the following DEBUG_WARN call after uncompress failure.

What do you suggest to do here, please? A cast to size_t in the print command sounds easily doable, what do you think? Otherwise I'm not familiar with arch-dependant format specifiers in the libpst, I know about those only in glib.

I do not see a compiler warning about the formats here (the build.log-s can be accessed in koji), but it can be either the DEBUG_WARN does not have set gcc attributes for it or it does not evaluate in the Fedora builds. I do not know.

Also, I think it would be best to use the zlib uLongf type

Interesting, I though the gcc warning uses verbatim code from the header file, but I see it expanded the macros. I did not know they have their own type for it.

pabs3 commented 7 months ago

Since zlib doesn't provide a define for the uLongf printf format specifier, a cast to size_t seems like the way to go.

I only found the extra type because I wasn't sure what the uncompress prototype was using, so went looking for it 😀️

mcrha commented 7 months ago

Okay, I made the change, with few more type casting, even that did not produce any compiler warning.